index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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: false}, 'no-js-errors/',
  30. lessTester.testErrors, null],
  31. [{math: 'strict', dumpLineNumbers: 'comments'}, 'debug/', null,
  32. function(name) { return name + '-comments'; }],
  33. [{math: 'strict', dumpLineNumbers: 'mediaquery'}, 'debug/', null,
  34. function(name) { return name + '-mediaquery'; }],
  35. [{math: 'strict', dumpLineNumbers: 'all'}, 'debug/', null,
  36. function(name) { return name + '-all'; }],
  37. // TODO: Change this to rewriteUrls: false once the relativeUrls option is removed
  38. [{math: 'strict', relativeUrls: false, rootpath: 'folder (1)/'}, 'static-urls/'],
  39. [{math: 'strict', compress: true}, 'compression/'],
  40. [{math: 0, strictUnits: true}, 'units/strict/'],
  41. [{math: 0, strictUnits: false}, 'units/no-strict/'],
  42. [{math: 'strict', strictUnits: true, sourceMap: true, globalVars: true }, 'sourcemaps/',
  43. lessTester.testSourcemap, null, null,
  44. function(filename, type, baseFolder) {
  45. if (type === 'vars') {
  46. return path.join(baseFolder, filename) + '.json';
  47. }
  48. return path.join('test/sourcemaps', filename) + '.json';
  49. }],
  50. [{math: 'strict', strictUnits: true, globalVars: true }, '_main/import/json/',
  51. lessTester.testImports, null, true,
  52. function(filename, type, baseFolder) {
  53. return path.join(baseFolder, filename) + '.json';
  54. }],
  55. [{math: 'strict', strictUnits: true, sourceMap: {sourceMapFileInline: true}},
  56. 'sourcemaps-empty/', lessTester.testEmptySourcemap],
  57. [{math: 'strict', strictUnits: true, sourceMap: {disableSourcemapAnnotation: true}},
  58. 'sourcemaps-disable-annotation/', lessTester.testSourcemapWithoutUrlAnnotation],
  59. [{globalVars: true, banner: '/**\n * Test\n */\n'}, 'globalVars/',
  60. null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
  61. [{modifyVars: true}, 'modifyVars/',
  62. null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
  63. [{urlArgs: '424242'}, 'url-args/'],
  64. [{rewriteUrls: 'all'}, 'rewrite-urls-all/'],
  65. [{rewriteUrls: 'local'}, 'rewrite-urls-local/'],
  66. [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'all'}, 'rootpath-rewrite-urls-all/'],
  67. [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'local'}, 'rootpath-rewrite-urls-local/'],
  68. [{paths: ['data/', '_main/import/']}, 'include-path/'],
  69. [{paths: 'data/'}, 'include-path-string/'],
  70. [{plugin: 'test/plugins/postprocess/'}, 'postProcessorPlugin/'],
  71. [{plugin: 'test/plugins/preprocess/'}, 'preProcessorPlugin/'],
  72. [{plugin: 'test/plugins/visitor/'}, 'visitorPlugin/'],
  73. [{plugin: 'test/plugins/filemanager/'}, 'filemanagerPlugin/'],
  74. [{math: 0}, '3rd-party/'],
  75. [{ processImports: false }, 'process-imports/']
  76. ];
  77. testMap.forEach(function(args) {
  78. lessTester.runTestSet.apply(lessTester, args)
  79. });
  80. lessTester.testSyncronous({syncImport: true}, '_main/import');
  81. lessTester.testSyncronous({syncImport: true}, '_main/plugin');
  82. lessTester.testSyncronous({syncImport: true}, 'math/strict/css');
  83. lessTester.testNoOptions();
  84. lessTester.testJSImport();
  85. lessTester.finished();
  86. (() => {
  87. // Create new tester, since tests are not independent and tests
  88. // above modify tester in a way that breaks remote imports.
  89. lessTester = lessTest();
  90. var scope = nock('https://example.com')
  91. .get('/redirect.less').query(true)
  92. .reply(301, null, { location: '/target.less' })
  93. .get('/target.less').query(true)
  94. .reply(200);
  95. lessTester.runTestSet(
  96. {},
  97. 'import-redirect/',
  98. lessTester.testImportRedirect(scope)
  99. );
  100. lessTester.finished();
  101. })();