From a10c3399d39efcd87c2650d172aefcf0703f70bb Mon Sep 17 00:00:00 2001 From: Lei Chen Date: Thu, 7 Oct 2021 06:58:01 +0800 Subject: [PATCH] chore: fix less project ci (#3652) * chore: fix less ci * fix: add missing semver require * fix: fix the error format and file path * chore: fix error format * chore: fix test snapshot * chore: fix error position --- packages/less/test/index.js | 3 +- packages/less/test/less-test.js | 28 ++++++++++++++++++- .../errors/eval/javascript-error.less | 3 -- .../errors/eval/javascript-error.txt | 4 --- .../less/js-type-errors/js-type-error-2.txt | 4 +++ .../less/js-type-errors/js-type-error.less | 3 ++ .../less/js-type-errors/js-type-error.txt | 4 +++ 7 files changed, 40 insertions(+), 9 deletions(-) delete mode 100644 packages/test-data/errors/eval/javascript-error.less delete mode 100644 packages/test-data/errors/eval/javascript-error.txt create mode 100644 packages/test-data/less/js-type-errors/js-type-error-2.txt create mode 100644 packages/test-data/less/js-type-errors/js-type-error.less create mode 100644 packages/test-data/less/js-type-errors/js-type-error.txt diff --git a/packages/less/test/index.js b/packages/less/test/index.js index 24f7e56cd..880d57ddd 100644 --- a/packages/less/test/index.js +++ b/packages/less/test/index.js @@ -28,7 +28,8 @@ var testMap = [ lessTester.testErrors, null], [{strictMath: true, strictUnits: true, javascriptEnabled: true}, '../errors/parse/', lessTester.testErrors, null], - + [{math: 'strict', strictUnits: true, javascriptEnabled: true}, 'js-type-errors/', + lessTester.testTypeErrors, null], [{math: 'strict', strictUnits: true, javascriptEnabled: false}, 'no-js-errors/', lessTester.testErrors, null], [{math: 'strict', dumpLineNumbers: 'comments'}, 'debug/', null, diff --git a/packages/less/test/less-test.js b/packages/less/test/less-test.js index c94e1c67b..ad7d6d7f9 100644 --- a/packages/less/test/less-test.js +++ b/packages/less/test/less-test.js @@ -1,5 +1,5 @@ /* jshint latedef: nofunc */ - +var semver = require('semver'); var logger = require('../lib/less/logger').default; var isVerbose = process.env.npm_config_loglevel !== 'concise'; @@ -226,6 +226,31 @@ module.exports = function() { }); } + // To fix ci fail about error format change in upstream v8 project + // https://github.com/v8/v8/commit/c0fd89c3c089e888c4f4e8582e56db7066fa779b + // Node 16.9.0+ include this change via https://github.com/nodejs/node/pull/39947 + function testTypeErrors(name, err, compiledLess, doReplacements, sourcemap, baseFolder) { + const fileSuffix = semver.gte(process.version, 'v16.9.0') ? '-2.txt' : '.txt'; + fs.readFile(path.join(baseFolder, name) + fileSuffix, 'utf8', function (e, expectedErr) { + process.stdout.write('- ' + path.join(baseFolder, name) + ': '); + expectedErr = doReplacements(expectedErr, baseFolder, err && err.filename); + if (!err) { + if (compiledLess) { + fail('No Error', 'red'); + } else { + fail('No Error, No Output'); + } + } else { + var errMessage = err.toString(); + if (errMessage === expectedErr) { + ok('OK'); + } else { + difference('FAIL', expectedErr, errMessage); + } + } + }); + } + // https://github.com/less/less.js/issues/3112 function testJSImport() { process.stdout.write('- Testing root function registry'); @@ -543,6 +568,7 @@ module.exports = function() { runTestSetNormalOnly: runTestSetNormalOnly, testSyncronous: testSyncronous, testErrors: testErrors, + testTypeErrors: testTypeErrors, testSourcemap: testSourcemap, testSourcemapWithoutUrlAnnotation: testSourcemapWithoutUrlAnnotation, testImports: testImports, diff --git a/packages/test-data/errors/eval/javascript-error.less b/packages/test-data/errors/eval/javascript-error.less deleted file mode 100644 index 9332a37d8..000000000 --- a/packages/test-data/errors/eval/javascript-error.less +++ /dev/null @@ -1,3 +0,0 @@ -.scope { - var: `this.foo.toJS`; -} diff --git a/packages/test-data/errors/eval/javascript-error.txt b/packages/test-data/errors/eval/javascript-error.txt deleted file mode 100644 index e5f7dc39e..000000000 --- a/packages/test-data/errors/eval/javascript-error.txt +++ /dev/null @@ -1,4 +0,0 @@ -SyntaxError: JavaScript evaluation error: 'TypeError: Cannot read property 'toJS' of undefined' in {path}javascript-error.less on line 2, column 10: -1 .scope { -2 var: `this.foo.toJS`; -3 } diff --git a/packages/test-data/less/js-type-errors/js-type-error-2.txt b/packages/test-data/less/js-type-errors/js-type-error-2.txt new file mode 100644 index 000000000..83c675fc5 --- /dev/null +++ b/packages/test-data/less/js-type-errors/js-type-error-2.txt @@ -0,0 +1,4 @@ +SyntaxError: JavaScript evaluation error: 'TypeError: Cannot read properties of undefined (reading 'toJS')' in {path}js-type-error.less on line 2, column 8: +1 .scope { +2 var: `this.foo.toJS`; +3 } diff --git a/packages/test-data/less/js-type-errors/js-type-error.less b/packages/test-data/less/js-type-errors/js-type-error.less new file mode 100644 index 000000000..1754d1655 --- /dev/null +++ b/packages/test-data/less/js-type-errors/js-type-error.less @@ -0,0 +1,3 @@ +.scope { + var: `this.foo.toJS`; +} diff --git a/packages/test-data/less/js-type-errors/js-type-error.txt b/packages/test-data/less/js-type-errors/js-type-error.txt new file mode 100644 index 000000000..68e35ceb7 --- /dev/null +++ b/packages/test-data/less/js-type-errors/js-type-error.txt @@ -0,0 +1,4 @@ +SyntaxError: JavaScript evaluation error: 'TypeError: Cannot read property 'toJS' of undefined' in {path}js-type-error.less on line 2, column 8: +1 .scope { +2 var: `this.foo.toJS`; +3 }