Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: bluelovers ka
Added: Nov 30, 2017 3:34 PM
Modified: Jun 6, 2019 1:15 PM
Views: 25
Tags: chai dev mocha test
  1. // @ts-ignore
  2. import _chai = require('chai');
  3. // @ts-ignore
  4. // @ts-ignore
  5. //import { expect, assert } from 'chai';
  6.  
  7. import { IChaiInstalled } from 'chai-asserttype-extra'
  8. //import ChaiPlugin = require('chai-asserttype-extra');
  9. import ChaiStatic = Chai.ChaiStatic;
  10.  
  11. let chai: IChaiInstalled<ChaiStatic> | ChaiStatic;
  12.  
  13. if (requireResolve('chai-asserttype-extra'))
  14. {
  15.         const ChaiPlugin = require('chai-asserttype-extra').ChaiPlugin;
  16.  
  17.         chai = ChaiPlugin.install(_chai) as IChaiInstalled<ChaiStatic>;
  18. }
  19. else
  20. {
  21.         chai = _chai;
  22. }
  23.  
  24. if (requireResolve('chai-string'))
  25. {
  26.         chai.use(require('chai-string'));
  27. }
  28.  
  29. const { expect, assert } = chai;
  30.  
  31. export { chai, expect, assert }
  32.  
  33. export const SymbolLogOutput = Symbol('output');
  34.  
  35. // @ts-ignore
  36. import path = require('path');
  37. // @ts-ignore
  38. import util = require('util');
  39.  
  40. // @ts-ignore
  41. (util.inspect.defaultOptions = util.inspect.defaultOptions || {}).colors = true;
  42.  
  43. export { path, util };
  44.  
  45. // @ts-ignore
  46. export const rootDir: string = path.join(__dirname, '..');
  47.  
  48. export function relative(filename: string): string
  49. {
  50.         return path.relative(rootDir, filename);
  51. }
  52.  
  53. export function mochaAsync(fn: Function)
  54. {
  55.         return async (done) =>
  56.         {
  57.                 try
  58.                 {
  59.                         await fn();
  60.                         done();
  61.                 }
  62.                 catch (err)
  63.                 {
  64.                         done(err);
  65.                 }
  66.         };
  67. }
  68.  
  69. export default exports as typeof import('./_local-dev');
  70.  
  71. export function requireResolve(name: string): string
  72. {
  73.         try
  74.         {
  75.                 return require.resolve(name)
  76.         }
  77.         catch (e)
  78.         {
  79.  
  80.         }
  81.         return null;
  82. }
  83.