index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var lessTest = require('./less-test'),
  2. lessTester = lessTest(),
  3. path = require('path'),
  4. stylize = require('../lib/less-node/lessc-helper').stylize,
  5. nock = require('nock');
  6. console.log('\n' + stylize('Less', 'underline') + '\n');
  7. var testMap = [
  8. [{
  9. // TODO: Change this to rewriteUrls: 'all' once the relativeUrls option is removed
  10. relativeUrls: true,
  11. silent: true,
  12. javascriptEnabled: true
  13. }, '_main/'],
  14. [{}, 'namespacing/'],
  15. [{
  16. math: 'parens'
  17. }, 'math/strict/'],
  18. [{
  19. math: 'parens-division'
  20. }, 'math/parens-division/'],
  21. [{
  22. math: 'always'
  23. }, 'math/always/'],
  24. // Use legacy strictMath: true here to demonstrate it still works
  25. [{strictMath: true, strictUnits: true, javascriptEnabled: true}, '../errors/eval/',
  26. lessTester.testErrors, null],
  27. [{strictMath: true, strictUnits: true, javascriptEnabled: true}, '../errors/parse/',
  28. lessTester.testErrors, null],
  29. [{math: 'strict', strictUnits: true, javascriptEnabled: true}, 'js-type-errors/',
  30. lessTester.testTypeErrors, null],
  31. [{math: 'strict', strictUnits: true, javascriptEnabled: false}, 'no-js-errors/',
  32. lessTester.testErrors, null],
  33. [{math: 'strict', dumpLineNumbers: 'comments'}, 'debug/', null,
  34. function(name) { return name + '-comments'; }],
  35. [{math: 'strict', dumpLineNumbers: 'mediaquery'}, 'debug/', null,
  36. function(name) { return name + '-mediaquery'; }],
  37. [{math: 'strict', dumpLineNumbers: 'all'}, 'debug/', null,
  38. function(name) { return name + '-all'; }],
  39. // TODO: Change this to rewriteUrls: false once the relativeUrls option is removed
  40. [{math: 'strict', relativeUrls: false, rootpath: 'folder (1)/'}, 'static-urls/'],
  41. [{math: 'strict', compress: true}, 'compression/'],
  42. [{math: 0, strictUnits: true}, 'units/strict/'],
  43. [{math: 0, strictUnits: false}, 'units/no-strict/'],
  44. [{math: 'strict', strictUnits: true, sourceMap: true, globalVars: true }, 'sourcemaps/',
  45. lessTester.testSourcemap, null, null,
  46. function(filename, type, baseFolder) {
  47. if (type === 'vars') {
  48. return path.join(baseFolder, filename) + '.json';
  49. }
  50. return path.join('test/sourcemaps', filename) + '.json';
  51. }],
  52. [{math: 'strict', strictUnits: true, globalVars: true }, '_main/import/json/',
  53. lessTester.testImports, null, true,
  54. function(filename, type, baseFolder) {
  55. return path.join(baseFolder, filename) + '.json';
  56. }],
  57. [{math: 'strict', strictUnits: true, sourceMap: {sourceMapFileInline: true}},
  58. 'sourcemaps-empty/', lessTester.testEmptySourcemap],
  59. [{math: 'strict', strictUnits: true, sourceMap: {disableSourcemapAnnotation: true}},
  60. 'sourcemaps-disable-annotation/', lessTester.testSourcemapWithoutUrlAnnotation],
  61. [{math: 'strict', strictUnits: true, sourceMap: true},
  62. 'sourcemaps-variable-selector/', lessTester.testSourcemapWithVariableInSelector],
  63. [{globalVars: true, banner: '/**\n * Test\n */\n'}, 'globalVars/',
  64. null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
  65. [{modifyVars: true}, 'modifyVars/',
  66. null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
  67. [{urlArgs: '424242'}, 'url-args/'],
  68. [{rewriteUrls: 'all'}, 'rewrite-urls-all/'],
  69. [{rewriteUrls: 'local'}, 'rewrite-urls-local/'],
  70. [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'all'}, 'rootpath-rewrite-urls-all/'],
  71. [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'local'}, 'rootpath-rewrite-urls-local/'],
  72. [{paths: ['data/', '_main/import/']}, 'include-path/'],
  73. [{paths: 'data/'}, 'include-path-string/'],
  74. [{plugin: 'test/plugins/postprocess/'}, 'postProcessorPlugin/'],
  75. [{plugin: 'test/plugins/preprocess/'}, 'preProcessorPlugin/'],
  76. [{plugin: 'test/plugins/visitor/'}, 'visitorPlugin/'],
  77. [{plugin: 'test/plugins/filemanager/'}, 'filemanagerPlugin/'],
  78. [{math: 0}, '3rd-party/'],
  79. [{ processImports: false }, 'process-imports/']
  80. ];
  81. testMap.forEach(function(args) {
  82. lessTester.runTestSet.apply(lessTester, args)
  83. });
  84. lessTester.testSyncronous({syncImport: true}, '_main/import');
  85. lessTester.testSyncronous({syncImport: true}, '_main/plugin');
  86. lessTester.testSyncronous({syncImport: true}, 'math/strict/css');
  87. lessTester.testNoOptions();
  88. lessTester.testDisablePluginRule();
  89. lessTester.testJSImport();
  90. lessTester.finished();
  91. (() => {
  92. // Create new tester, since tests are not independent and tests
  93. // above modify tester in a way that breaks remote imports.
  94. lessTester = lessTest();
  95. var scope = nock('https://example.com')
  96. .get('/redirect.less').query(true)
  97. .reply(301, null, { location: '/target.less' })
  98. .get('/target.less').query(true)
  99. .reply(200);
  100. lessTester.runTestSet(
  101. {},
  102. 'import-redirect/',
  103. lessTester.testImportRedirect(scope)
  104. );
  105. lessTester.finished();
  106. })();