Skip to content

Commit

Permalink
Make scss tests work on Windows too. (#37713)
Browse files Browse the repository at this point in the history
Also, add missing `'use strict'` statements; these aren't real modules.
  • Loading branch information
XhmikosR authored Dec 25, 2022
1 parent fa37da4 commit d891159
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
13 changes: 7 additions & 6 deletions scss/tests/jasmine.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
11 changes: 8 additions & 3 deletions scss/tests/sass-true/register.js
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 5 additions & 3 deletions scss/tests/sass-true/runner.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit d891159

Please sign in to comment.