Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 16 additions & 17 deletions packages/less/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var resolve = require('resolve');
var path = require('path');

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

module.exports = function(grunt) {
grunt.option("stack", true);
Expand Down Expand Up @@ -85,8 +85,7 @@ module.exports = function(grunt) {
"relative-urls",
"rewrite-urls",
"browser",
"no-js-errors",
"legacy"
"no-js-errors"
];

function makeJob(testName) {
Expand Down Expand Up @@ -214,7 +213,7 @@ module.exports = function(grunt) {
command: "node build/rollup.js --browser --out=./tmp/browser/less.min.js"
},
test: {
command: 'ts-node test/test-es6.ts && node test/index.js'
command: 'npx ts-node test/test-es6.ts && node test/index.js'
},
generatebrowser: {
command: 'node test/browser/generator/generate.js'
Expand All @@ -230,35 +229,35 @@ module.exports = function(grunt) {
command: [
// @TODO: make this more thorough
// CURRENT OPTIONS
`node bin/lessc --ie-compat ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --ie-compat ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
// --math
`node bin/lessc --math=always ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens-division ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict-legacy ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=always ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens-division ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict-legacy ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,

// DEPRECATED OPTIONS
// --strict-math
`node bin/lessc --strict-math=on ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`
`node bin/lessc --strict-math=on ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`
].join(" && ")
},
plugin: {
command: [
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
"cd lib",
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/tests-unit/lazy-eval/lazy-eval.less ../tmp/lazy-eval.css`,
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/tests-unit/lazy-eval/lazy-eval.less ../tmp/lazy-eval.css`,
"cd ..",
// Test multiple plugins
`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`
`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`
].join(" && ")
},
"sourcemap-test": {
// quoted value doesn't seem to get picked up by time-grunt, or isn't output, at least; maybe just "sourcemap" is fine?
command: [
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/_main/import.less test/sourcemaps/import.css`,
`node bin/lessc --source-map ${lessFolder}/sourcemaps/basic.less test/sourcemaps/basic.css`
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/tests-unit/import/import.less test/sourcemaps/import.css`,
`node bin/lessc --source-map ${lessFolder}/tests-config/sourcemaps/basic.less test/sourcemaps/basic.css`
].join(" && ")
}
},
Expand Down
11 changes: 7 additions & 4 deletions packages/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
"compile": "tsc -p tsconfig.build.json",
"dev": "tsc -p tsconfig.build.json -w",
"prepublishOnly": "grunt dist"
"prepublishOnly": "grunt dist",
"postinstall": "node scripts/postinstall.js"
},
"optionalDependencies": {
"errno": "^0.1.1",
Expand All @@ -66,11 +67,13 @@
"benny": "^3.6.12",
"bootstrap-less-port": "0.3.0",
"chai": "^4.2.0",
"chalk": "^4.1.2",
"cosmiconfig": "~9.0.0",
"cross-env": "^7.0.3",
"diff": "^3.2.0",
"eslint": "^7.29.0",
"fs-extra": "^8.1.0",
"git-rev": "^0.2.1",
"glob": "~11.0.3",
"globby": "^10.0.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
Expand All @@ -80,17 +83,17 @@
"grunt-saucelabs": "^9.0.1",
"grunt-shell": "^1.3.0",
"html-template-tag": "^3.2.0",
"jest-diff": "~30.1.2",
"jit-grunt": "^0.10.0",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.6.0",
"minimist": "^1.2.0",
"mocha": "^6.2.1",
"playwright": "1.50.1",
"mocha-teamcity-reporter": "^3.0.0",
"nock": "^11.8.2",
"npm-run-all": "^4.1.5",
"performance-now": "^0.2.0",
"phin": "^2.2.3",
"playwright": "1.50.1",
"promise": "^7.1.1",
"read-glob": "^3.0.0",
"resolve": "^1.17.0",
Expand Down
61 changes: 61 additions & 0 deletions packages/less/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node

/**
* Post-install script for Less.js package
*
* This script installs Playwright browsers only when:
* 1. This is a development environment (not when installed as a dependency)
* 2. We're in a monorepo context (parent package.json exists)
* 3. Not running in CI or other automated environments
*/

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Check if we're in a development environment
function isDevelopmentEnvironment() {
// Skip if this is a global install or user config
if (process.env.npm_config_user_config || process.env.npm_config_global) {
return false;
}

// Skip in CI environments
if (process.env.CI || process.env.GITHUB_ACTIONS || process.env.TRAVIS) {
return false;
}

// Check if we're in a monorepo (parent package.json exists)
const parentPackageJson = path.join(__dirname, '../../../package.json');
if (!fs.existsSync(parentPackageJson)) {
return false;
}

// Check if this is the root of the monorepo
const currentPackageJson = path.join(__dirname, '../package.json');
if (!fs.existsSync(currentPackageJson)) {
return false;
}

return true;
}

// Install Playwright browsers
function installPlaywrightBrowsers() {
try {
console.log('🎭 Installing Playwright browsers for development...');
execSync('pnpm exec playwright install', {
stdio: 'inherit',
cwd: path.join(__dirname, '..')
});
console.log('✅ Playwright browsers installed successfully');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is handy, thanks!

} catch (error) {
console.warn('⚠️ Failed to install Playwright browsers:', error.message);
console.warn(' You can install them manually with: pnpm exec playwright install');
}
}

// Main execution
if (isDevelopmentEnvironment()) {
installPlaywrightBrowsers();
}
1 change: 1 addition & 0 deletions packages/less/test.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.test { color: red; }
2 changes: 1 addition & 1 deletion packages/less/test/browser/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ testErrorSheet = function (sheet) {
errorTxt = errorTxt
.replace(/\{path\}/g, '')
.replace(/\{pathrel\}/g, '')
.replace(/\{pathhref\}/g, 'http://localhost:8081/test/less/errors/')
.replace(/\{pathhref\}/g, 'http://localhost:8081/packages/less/node_modules/@less/test-data/tests-error/eval/')
.replace(/\{404status\}/g, ' (404)')
.replace(/\{node\}[\s\S]*\{\/node\}/g, '')
.replace(/\n$/, '')
Expand Down
42 changes: 18 additions & 24 deletions packages/less/test/browser/generator/runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@ var { forceCovertToBrowserPath } = require('./utils');

/** Root of repo */
var testFolder = forceCovertToBrowserPath(path.dirname(resolve.sync('@less/test-data')));
var lessFolder = forceCovertToBrowserPath(path.join(testFolder, 'less'));
var testsUnitFolder = forceCovertToBrowserPath(path.join(testFolder, 'tests-unit'));
var testsConfigFolder = forceCovertToBrowserPath(path.join(testFolder, 'tests-config'));
var localTests = forceCovertToBrowserPath(path.resolve(__dirname, '..'));

module.exports = {
main: {
// src is used to build list of less files to compile
src: [
`${lessFolder}/_main/*.less`,
`!${lessFolder}/_main/plugin-preeval.less`, // uses ES6 syntax
`${testsUnitFolder}/*/*.less`,
`!${testsUnitFolder}/plugin-preeval/plugin-preeval.less`, // uses ES6 syntax
// Don't test NPM import, obviously
`!${lessFolder}/_main/plugin-module.less`,
`!${lessFolder}/_main/import-module.less`,
`!${lessFolder}/_main/javascript.less`,
`!${lessFolder}/_main/urls.less`,
`!${lessFolder}/_main/empty.less`
`!${testsUnitFolder}/plugin-module/plugin-module.less`,
`!${testsUnitFolder}/import/import-module.less`,
`!${testsUnitFolder}/javascript/javascript.less`,
`!${testsUnitFolder}/urls/urls.less`,
`!${testsUnitFolder}/empty/empty.less`,
`!${testsUnitFolder}/color-functions/operations.less` // conflicts with operations/operations.less
],
options: {
helpers: 'test/browser/runner-main-options.js',
specs: 'test/browser/runner-main-spec.js',
outfile: 'tmp/browser/test-runner-main.html'
}
},
legacy: {
src: [`${lessFolder}/legacy/*.less`],
options: {
helpers: 'test/browser/runner-legacy-options.js',
specs: 'test/browser/runner-legacy-spec.js',
outfile: 'tmp/browser/test-runner-legacy.html'
}
},
strictUnits: {
src: [`${lessFolder}/units/strict/*.less`],
src: [`${testsConfigFolder}/units/strict/*.less`],
options: {
helpers: 'test/browser/runner-strict-units-options.js',
specs: 'test/browser/runner-strict-units-spec.js',
Expand All @@ -44,8 +38,8 @@ module.exports = {
},
errors: {
src: [
`${lessFolder}/errors/*.less`,
`${testFolder}/errors/javascript-error.less`,
`${testFolder}/tests-error/eval/*.less`,
`${testFolder}/tests-error/parse/*.less`,
`${localTests}/less/errors/*.less`
],
options: {
Expand All @@ -56,7 +50,7 @@ module.exports = {
}
},
noJsErrors: {
src: [`${lessFolder}/no-js-errors/*.less`],
src: [`${testsConfigFolder}/no-js-errors/*.less`],
options: {
helpers: 'test/browser/runner-no-js-errors-options.js',
specs: 'test/browser/runner-no-js-errors-spec.js',
Expand Down Expand Up @@ -141,7 +135,7 @@ module.exports = {
}
},
postProcessorPlugin: {
src: [`${lessFolder}/postProcessorPlugin/*.less`],
src: [`${testsConfigFolder}/postProcessorPlugin/*.less`],
options: {
helpers: [
'test/plugins/postprocess/index.js',
Expand All @@ -153,7 +147,7 @@ module.exports = {
}
},
preProcessorPlugin: {
src: [`${lessFolder}/preProcessorPlugin/*.less`],
src: [`${testsConfigFolder}/preProcessorPlugin/*.less`],
options: {
helpers: [
'test/plugins/preprocess/index.js',
Expand All @@ -164,7 +158,7 @@ module.exports = {
}
},
visitorPlugin: {
src: [`${lessFolder}/visitorPlugin/*.less`],
src: [`${testsConfigFolder}/visitorPlugin/*.less`],
options: {
helpers: [
'test/plugins/visitor/index.js',
Expand All @@ -175,7 +169,7 @@ module.exports = {
}
},
filemanagerPlugin: {
src: [`${lessFolder}/filemanagerPlugin/*.less`],
src: [`${testsConfigFolder}/filemanagerPlugin/*.less`],
options: {
helpers: [
'test/plugins/filemanager/index.js',
Expand Down
17 changes: 14 additions & 3 deletions packages/less/test/browser/generator/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ module.exports = (stylesheets, helpers, spec, less) => {
<!-- for each test, generate CSS/LESS link tags -->
$${stylesheets.map(function(fullLessName) {
var pathParts = fullLessName.split('/');
var fullCssName = fullLessName
.replace(/\/(browser|test-data)\/less\//g, '/$1/css/')
.replace(/less$/, 'css')
var fullCssName = fullLessName.replace(/less$/, 'css');

// Check if the CSS file exists in the same directory as the LESS file
var fs = require('fs');
var cssExists = fs.existsSync(fullCssName);

// If not, try the css/ directory for local browser tests
if (!cssExists && fullLessName.includes('/test/browser/less/')) {
var cssInCssDir = fullLessName.replace('/test/browser/less/', '/test/browser/css/').replace(/less$/, 'css');
if (fs.existsSync(cssInCssDir)) {
fullCssName = cssInCssDir;
}
}

var lessName = pathParts[pathParts.length - 1];
var name = lessName.split('.')[0];
return `
Expand Down
10 changes: 5 additions & 5 deletions packages/less/test/browser/runner-browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ var less = {
};

// test inline less in style tags by grabbing an assortment of less files and doing `@import`s
var testFiles = ['charsets', 'colors', 'comments', 'css-3', 'strings', 'media', 'mixins'],
var testFiles = ['charsets/charsets', 'color-functions/basic', 'comments/comments', 'css-3/css-3', 'strings/strings', 'media/media', 'mixins/mixins'],
testSheets = [];

// setup style tags with less and link tags pointing to expected css output

/**
* @todo - generate the node_modules path for this file and in templates
*/
var lessFolder = '../../node_modules/@less/test-data/less'
var cssFolder = '../../node_modules/@less/test-data/css'
var lessFolder = '../../node_modules/@less/test-data/tests-unit'
var cssFolder = '../../node_modules/@less/test-data/tests-unit'

for (var i = 0; i < testFiles.length; i++) {
var file = testFiles[i],
lessPath = lessFolder + '/_main/' + file + '.less',
cssPath = cssFolder + '/_main/' + file + '.css',
lessPath = lessFolder + '/' + file + '.less',
cssPath = cssFolder + '/' + file + '.css',
lessStyle = document.createElement('style'),
cssLink = document.createElement('link'),
lessText = '@import "' + lessPath + '";';
Expand Down
6 changes: 0 additions & 6 deletions packages/less/test/browser/runner-legacy-options.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/less/test/browser/runner-legacy-spec.js

This file was deleted.

Loading
Loading