From d891159950f695c69761551715fee5182a008d33 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 25 Dec 2022 18:09:26 +0200 Subject: [PATCH] Make scss tests work on Windows too. (#37713) Also, add missing `'use strict'` statements; these aren't real modules. --- scss/tests/jasmine.js | 13 +++++++------ scss/tests/sass-true/register.js | 11 ++++++++--- scss/tests/sass-true/runner.js | 8 +++++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/scss/tests/jasmine.js b/scss/tests/jasmine.js index e1b09adf5cc3..dd78aa5511db 100644 --- a/scss/tests/jasmine.js +++ b/scss/tests/jasmine.js @@ -1,16 +1,17 @@ /* eslint-env node */ -const path = require('node:path') +/* eslint-disable camelcase */ -module.exports = { - spec_dir: 'scss' /* eslint-disable-line camelcase */, +'use strict' - // Make Mocha look for `.test.scss` files - spec_files: ['**/*.{test,spec}.scss'] /* eslint-disable-line camelcase */, +const path = require('node:path') +module.exports = { + spec_dir: 'scss', + // Make Jasmine look for `.test.scss` files + spec_files: ['**/*.{test,spec}.scss'], // Compile them into JS scripts running `sass-true` requires: [path.join(__dirname, 'sass-true/register')], - // Ensure we use `require` so that the require.extensions works // as `import` completely bypasses it jsLoader: 'require' diff --git a/scss/tests/sass-true/register.js b/scss/tests/sass-true/register.js index 50c9c415e2ee..bf4139ab1156 100644 --- a/scss/tests/sass-true/register.js +++ b/scss/tests/sass-true/register.js @@ -1,10 +1,15 @@ /* eslint-env node */ -const runnerPath = require('node:path').join(__dirname, 'runner') +'use strict' + +const path = require('node:path') +const runnerPath = path.join(__dirname, 'runner').replace(/\\/g, '/') + +require.extensions['.scss'] = (module, filename) => { + const normalizedFilename = filename.replace(/\\/g, '/') -require.extensions['.scss'] = function (module, filename) { return module._compile(` const runner = require('${runnerPath}') - runner('${filename}',{describe, it}) + runner('${normalizedFilename}', { describe, it }) `, filename) } diff --git a/scss/tests/sass-true/runner.js b/scss/tests/sass-true/runner.js index 96766938cd7b..44d8da99dbed 100644 --- a/scss/tests/sass-true/runner.js +++ b/scss/tests/sass-true/runner.js @@ -1,12 +1,14 @@ /* eslint-env node */ +'use strict' + const { runSass } = require('sass-true') const fs = require('node:fs') const path = require('node:path') -module.exports = function (filename, { describe, it }) { - const data = fs.readFileSync(filename, { encoding: 'utf8' }) - const TRUE_SETUP = '$true-terminal-output: false; @import \'true\';' +module.exports = (filename, { describe, it }) => { + const data = fs.readFileSync(filename, 'utf8') + const TRUE_SETUP = '$true-terminal-output: false; @import "true";' runSass({ data: TRUE_SETUP + data,