Skip to content

Commit 4322869

Browse files
authored
[Needs reviews!] Mega test refactor (#4378)
* Migrate Less to use valid CSS * Re-organize test structure * Lots of test refactoring * More test updates * Add restructured tests * WIP Signed-off-by: Matthew Dean <matthew-dean@users.noreply.github.com> * More fixes to tests * More test fixes * All tests passing * WIP fix tests * Finished fixing browser tests * Improve test coverage * Add debug tests * Add back debug tests to show equal test coverage * Fix browser tests * More test coverage * Fix sourcemap absolute path for CI * More source map normalization for Windows * Fix source map normalization * Another attempted fix for Windows --------- Signed-off-by: Matthew Dean <matthew-dean@users.noreply.github.com>
1 parent 1bde4bd commit 4322869

File tree

648 files changed

+4813
-1158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

648 files changed

+4813
-1158
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212
node_modules
1313
!package-lock.json
1414
npm-debug.log
15+
16+
# Coverage
17+
.nyc_output
18+
coverage
19+
*.lcov

packages/less/Gruntfile.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var resolve = require('resolve');
44
var path = require('path');
55

66
var testFolder = path.relative(process.cwd(), path.dirname(resolve.sync('@less/test-data')));
7-
var lessFolder = path.join(testFolder, 'less');
7+
var lessFolder = testFolder;
88

99
module.exports = function(grunt) {
1010
grunt.option("stack", true);
@@ -85,8 +85,7 @@ module.exports = function(grunt) {
8585
"relative-urls",
8686
"rewrite-urls",
8787
"browser",
88-
"no-js-errors",
89-
"legacy"
88+
"no-js-errors"
9089
];
9190

9291
function makeJob(testName) {
@@ -214,7 +213,7 @@ module.exports = function(grunt) {
214213
command: "node build/rollup.js --browser --out=./tmp/browser/less.min.js"
215214
},
216215
test: {
217-
command: 'ts-node test/test-es6.ts && node test/index.js'
216+
command: 'npx ts-node test/test-es6.ts && node test/index.js'
218217
},
219218
generatebrowser: {
220219
command: 'node test/browser/generator/generate.js'
@@ -230,35 +229,35 @@ module.exports = function(grunt) {
230229
command: [
231230
// @TODO: make this more thorough
232231
// CURRENT OPTIONS
233-
`node bin/lessc --ie-compat ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
232+
`node bin/lessc --ie-compat ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
234233
// --math
235-
`node bin/lessc --math=always ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
236-
`node bin/lessc --math=parens-division ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
237-
`node bin/lessc --math=parens ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
238-
`node bin/lessc --math=strict ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
239-
`node bin/lessc --math=strict-legacy ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
234+
`node bin/lessc --math=always ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
235+
`node bin/lessc --math=parens-division ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
236+
`node bin/lessc --math=parens ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
237+
`node bin/lessc --math=strict ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
238+
`node bin/lessc --math=strict-legacy ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
240239

241240
// DEPRECATED OPTIONS
242241
// --strict-math
243-
`node bin/lessc --strict-math=on ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`
242+
`node bin/lessc --strict-math=on ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`
244243
].join(" && ")
245244
},
246245
plugin: {
247246
command: [
248-
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
247+
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
249248
"cd lib",
250-
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
251-
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
249+
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/tests-unit/lazy-eval/lazy-eval.less ../tmp/lazy-eval.css`,
250+
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/tests-unit/lazy-eval/lazy-eval.less ../tmp/lazy-eval.css`,
252251
"cd ..",
253252
// Test multiple plugins
254-
`node bin/lessc --plugin=clean-css="--s1 --advanced" --plugin=autoprefix="ie 11,Edge >= 13,Chrome >= 47,Firefox >= 45,iOS >= 9.2,Safari >= 9" ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`
253+
`node bin/lessc --plugin=clean-css="--s1 --advanced" --plugin=autoprefix="ie 11,Edge >= 13,Chrome >= 47,Firefox >= 45,iOS >= 9.2,Safari >= 9" ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`
255254
].join(" && ")
256255
},
257256
"sourcemap-test": {
258257
// quoted value doesn't seem to get picked up by time-grunt, or isn't output, at least; maybe just "sourcemap" is fine?
259258
command: [
260-
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/_main/import.less test/sourcemaps/import.css`,
261-
`node bin/lessc --source-map ${lessFolder}/sourcemaps/basic.less test/sourcemaps/basic.css`
259+
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/tests-unit/import/import.less test/sourcemaps/import.css`,
260+
`node bin/lessc --source-map ${lessFolder}/tests-config/sourcemaps/basic.less test/sourcemaps/basic.css`
262261
].join(" && ")
263262
}
264263
},

packages/less/bin/lessc

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,53 +98,48 @@ function render() {
9898
}
9999

100100
if (options.sourceMap) {
101-
sourceMapOptions.sourceMapInputFilename = input;
102-
103-
if (!sourceMapOptions.sourceMapFullFilename) {
104-
if (!output && !sourceMapFileInline) {
105-
console.error('the sourcemap option only has an optional filename if the css filename is given');
106-
console.error('consider adding --source-map-map-inline which embeds the sourcemap into the css');
107-
process.exitCode = 1;
108-
return;
109-
} // its in the same directory, so always just the basename
110-
111-
112-
if (output) {
113-
sourceMapOptions.sourceMapOutputFilename = path.basename(output);
114-
sourceMapOptions.sourceMapFullFilename = ''.concat(output, '.map');
115-
} // its in the same directory, so always just the basename
116-
117-
118-
if ('sourceMapFullFilename' in sourceMapOptions) {
119-
sourceMapOptions.sourceMapFilename = path.basename(sourceMapOptions.sourceMapFullFilename);
120-
}
121-
} else if (options.sourceMap && !sourceMapFileInline) {
122-
var mapFilename = path.resolve(process.cwd(), sourceMapOptions.sourceMapFullFilename);
123-
var mapDir = path.dirname(mapFilename);
124-
var outputDir = path.dirname(output); // find the path from the map to the output file
125-
126-
// eslint-disable-next-line max-len
127-
sourceMapOptions.sourceMapOutputFilename = path.join(path.relative(mapDir, outputDir), path.basename(output)); // make the sourcemap filename point to the sourcemap relative to the css file output directory
128-
129-
sourceMapOptions.sourceMapFilename = path.join(path.relative(outputDir, mapDir), path.basename(sourceMapOptions.sourceMapFullFilename));
130-
}
131-
101+
// Validate conflicting options
132102
if (sourceMapOptions.sourceMapURL && sourceMapOptions.disableSourcemapAnnotation) {
133103
console.error('You cannot provide flag --source-map-url with --source-map-no-annotation.');
134104
console.error('Please remove one of those flags.');
135105
process.exitcode = 1;
136106
return;
137107
}
138-
}
139-
140-
if (sourceMapOptions.sourceMapBasepath === undefined) {
141-
sourceMapOptions.sourceMapBasepath = input ? path.dirname(input) : process.cwd();
142-
}
143108

144-
if (sourceMapOptions.sourceMapRootpath === undefined) {
145-
var pathToMap = path.dirname((sourceMapFileInline ? output : sourceMapOptions.sourceMapFullFilename) || '.');
146-
var pathToInput = path.dirname(sourceMapOptions.sourceMapInputFilename || '.');
147-
sourceMapOptions.sourceMapRootpath = path.relative(pathToMap, pathToInput);
109+
// Handle explicit sourceMapFullFilename (from --source-map=filename)
110+
// Normalization of other options (sourceMapBasepath, sourceMapRootpath, etc.)
111+
// is handled automatically in parse-tree.js
112+
if (sourceMapOptions.sourceMapFullFilename && !sourceMapFileInline) {
113+
var mapFilename = path.resolve(process.cwd(), sourceMapOptions.sourceMapFullFilename);
114+
var mapDir = path.dirname(mapFilename);
115+
116+
if (output) {
117+
var outputDir = path.dirname(output);
118+
// Set sourceMapOutputFilename relative to map directory
119+
sourceMapOptions.sourceMapOutputFilename = path.join(
120+
path.relative(mapDir, outputDir),
121+
path.basename(output)
122+
);
123+
// Set sourceMapFilename relative to output directory (for sourceMappingURL comment)
124+
sourceMapOptions.sourceMapFilename = path.join(
125+
path.relative(outputDir, mapDir),
126+
path.basename(sourceMapOptions.sourceMapFullFilename)
127+
);
128+
} else {
129+
// No output filename, just use basename
130+
sourceMapOptions.sourceMapOutputFilename = path.basename(output || 'output.css');
131+
sourceMapOptions.sourceMapFilename = path.basename(sourceMapOptions.sourceMapFullFilename);
132+
}
133+
} else if (!sourceMapOptions.sourceMapFullFilename && output && !sourceMapFileInline) {
134+
// No explicit sourcemap filename, derive from output
135+
sourceMapOptions.sourceMapOutputFilename = path.basename(output);
136+
sourceMapOptions.sourceMapFullFilename = ''.concat(output, '.map');
137+
} else if (!output && !sourceMapFileInline) {
138+
console.error('the sourcemap option only has an optional filename if the css filename is given');
139+
console.error('consider adding --source-map-map-inline which embeds the sourcemap into the css');
140+
process.exitCode = 1;
141+
return;
142+
}
148143
}
149144

150145
if (!input) {

packages/less/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@
3737
"scripts": {
3838
"quicktest": "grunt quicktest",
3939
"test": "grunt test",
40+
"test:coverage": "c8 -r lcov -r json-summary -r text-summary -r html --include=\"lib/**/*.js\" --include=\"bin/**/*.js\" --exclude=\"dist/**\" --exclude=\"**/*.test.js\" --exclude=\"**/*.spec.js\" --exclude=\"test/**\" --exclude=\"tmp/**\" --exclude=\"**/abstract-file-manager.js\" --exclude=\"**/abstract-plugin-loader.js\" grunt shell:test && node scripts/coverage-report.js && node scripts/coverage-lines.js",
4041
"grunt": "grunt",
4142
"lint": "eslint '**/*.{ts,js}'",
4243
"lint:fix": "eslint '**/*.{ts,js}' --fix",
4344
"build": "npm-run-all clean compile",
4445
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
4546
"compile": "tsc -p tsconfig.build.json",
4647
"dev": "tsc -p tsconfig.build.json -w",
47-
"prepublishOnly": "grunt dist"
48+
"prepublishOnly": "grunt dist",
49+
"postinstall": "node scripts/postinstall.js"
4850
},
4951
"optionalDependencies": {
5052
"errno": "^0.1.1",
@@ -66,11 +68,14 @@
6668
"benny": "^3.6.12",
6769
"bootstrap-less-port": "0.3.0",
6870
"chai": "^4.2.0",
71+
"c8": "^10.1.3",
72+
"chalk": "^4.1.2",
73+
"cosmiconfig": "~9.0.0",
6974
"cross-env": "^7.0.3",
70-
"diff": "^3.2.0",
7175
"eslint": "^7.29.0",
7276
"fs-extra": "^8.1.0",
7377
"git-rev": "^0.2.1",
78+
"glob": "~11.0.3",
7479
"globby": "^10.0.1",
7580
"grunt": "^1.0.4",
7681
"grunt-cli": "^1.3.2",
@@ -80,17 +85,17 @@
8085
"grunt-saucelabs": "^9.0.1",
8186
"grunt-shell": "^1.3.0",
8287
"html-template-tag": "^3.2.0",
88+
"jest-diff": "~30.1.2",
8389
"jit-grunt": "^0.10.0",
8490
"less-plugin-autoprefix": "^1.5.1",
8591
"less-plugin-clean-css": "^1.6.0",
8692
"minimist": "^1.2.0",
8793
"mocha": "^6.2.1",
88-
"playwright": "1.50.1",
8994
"mocha-teamcity-reporter": "^3.0.0",
90-
"nock": "^11.8.2",
9195
"npm-run-all": "^4.1.5",
9296
"performance-now": "^0.2.0",
9397
"phin": "^2.2.3",
98+
"playwright": "1.50.1",
9499
"promise": "^7.1.1",
95100
"read-glob": "^3.0.0",
96101
"resolve": "^1.17.0",

0 commit comments

Comments
 (0)