Skip to content

Commit a10c339

Browse files
authored
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
1 parent 8363912 commit a10c339

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

Diff for: packages/less/test/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var testMap = [
2828
lessTester.testErrors, null],
2929
[{strictMath: true, strictUnits: true, javascriptEnabled: true}, '../errors/parse/',
3030
lessTester.testErrors, null],
31-
31+
[{math: 'strict', strictUnits: true, javascriptEnabled: true}, 'js-type-errors/',
32+
lessTester.testTypeErrors, null],
3233
[{math: 'strict', strictUnits: true, javascriptEnabled: false}, 'no-js-errors/',
3334
lessTester.testErrors, null],
3435
[{math: 'strict', dumpLineNumbers: 'comments'}, 'debug/', null,

Diff for: packages/less/test/less-test.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* jshint latedef: nofunc */
2-
2+
var semver = require('semver');
33
var logger = require('../lib/less/logger').default;
44

55
var isVerbose = process.env.npm_config_loglevel !== 'concise';
@@ -226,6 +226,31 @@ module.exports = function() {
226226
});
227227
}
228228

229+
// To fix ci fail about error format change in upstream v8 project
230+
// https://github.com/v8/v8/commit/c0fd89c3c089e888c4f4e8582e56db7066fa779b
231+
// Node 16.9.0+ include this change via https://github.com/nodejs/node/pull/39947
232+
function testTypeErrors(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
233+
const fileSuffix = semver.gte(process.version, 'v16.9.0') ? '-2.txt' : '.txt';
234+
fs.readFile(path.join(baseFolder, name) + fileSuffix, 'utf8', function (e, expectedErr) {
235+
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
236+
expectedErr = doReplacements(expectedErr, baseFolder, err && err.filename);
237+
if (!err) {
238+
if (compiledLess) {
239+
fail('No Error', 'red');
240+
} else {
241+
fail('No Error, No Output');
242+
}
243+
} else {
244+
var errMessage = err.toString();
245+
if (errMessage === expectedErr) {
246+
ok('OK');
247+
} else {
248+
difference('FAIL', expectedErr, errMessage);
249+
}
250+
}
251+
});
252+
}
253+
229254
// https://github.com/less/less.js/issues/3112
230255
function testJSImport() {
231256
process.stdout.write('- Testing root function registry');
@@ -543,6 +568,7 @@ module.exports = function() {
543568
runTestSetNormalOnly: runTestSetNormalOnly,
544569
testSyncronous: testSyncronous,
545570
testErrors: testErrors,
571+
testTypeErrors: testTypeErrors,
546572
testSourcemap: testSourcemap,
547573
testSourcemapWithoutUrlAnnotation: testSourcemapWithoutUrlAnnotation,
548574
testImports: testImports,

Diff for: packages/test-data/errors/eval/javascript-error.less

-3
This file was deleted.

Diff for: packages/test-data/errors/eval/javascript-error.txt

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SyntaxError: JavaScript evaluation error: 'TypeError: Cannot read properties of undefined (reading 'toJS')' in {path}js-type-error.less on line 2, column 8:
2+
1 .scope {
3+
2 var: `this.foo.toJS`;
4+
3 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.scope {
2+
var: `this.foo.toJS`;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SyntaxError: JavaScript evaluation error: 'TypeError: Cannot read property 'toJS' of undefined' in {path}js-type-error.less on line 2, column 8:
2+
1 .scope {
3+
2 var: `this.foo.toJS`;
4+
3 }

0 commit comments

Comments
 (0)