Skip to content

Commit

Permalink
chore: fix less project ci (#3652)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iChenLei authored Oct 6, 2021
1 parent 8363912 commit a10c339
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/less/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 27 additions & 1 deletion packages/less/test/less-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -543,6 +568,7 @@ module.exports = function() {
runTestSetNormalOnly: runTestSetNormalOnly,
testSyncronous: testSyncronous,
testErrors: testErrors,
testTypeErrors: testTypeErrors,
testSourcemap: testSourcemap,
testSourcemapWithoutUrlAnnotation: testSourcemapWithoutUrlAnnotation,
testImports: testImports,
Expand Down
3 changes: 0 additions & 3 deletions packages/test-data/errors/eval/javascript-error.less

This file was deleted.

4 changes: 0 additions & 4 deletions packages/test-data/errors/eval/javascript-error.txt

This file was deleted.

4 changes: 4 additions & 0 deletions packages/test-data/less/js-type-errors/js-type-error-2.txt
Original file line number Diff line number Diff line change
@@ -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 }
3 changes: 3 additions & 0 deletions packages/test-data/less/js-type-errors/js-type-error.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.scope {
var: `this.foo.toJS`;
}
4 changes: 4 additions & 0 deletions packages/test-data/less/js-type-errors/js-type-error.txt
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit a10c339

Please sign in to comment.