Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scss tests work on Windows too #37713

Merged
merged 2 commits into from
Dec 25, 2022
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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