Skip to content

Commit

Permalink
Apply “Using Sass with Jest” environment guidance
Browse files Browse the repository at this point in the history
Preparation work for Dart Sass since JavaScript compiled from Dart requires real Node.js globals which Jest doesn’t use

https://github.com/sass/dart-sass#using-sass-with-jest
jestjs/jest#2549
  • Loading branch information
colinrotherham committed Jan 20, 2023
1 parent 4a6f0cb commit 4106a2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 7 additions & 4 deletions config/jest/environment/node.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TestEnvironment } from 'jest-environment-node'
import SingleContextNodeEnvironment from 'jest-environment-node-single-context'

import { globals } from '../globals.mjs'

/**
* Default Node.js environment
* Adds shared test globals
* Single context Node.js environment
* Adds real Node.js test globals for Dart Sass
*
* {@link https://github.com/sass/dart-sass#using-sass-with-jest}
* {@link https://github.com/facebook/jest/issues/2549}
*/
class NodeEnvironment extends TestEnvironment {
class NodeEnvironment extends SingleContextNodeEnvironment {
async setup () {
await super.setup()

Expand Down
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"jest-axe": "^7.0.0",
"jest-dev-server": "^6.2.0",
"jest-environment-jsdom": "^29.3.1",
"jest-environment-node": "^29.3.1",
"jest-environment-node-single-context": "^29.0.0",
"jest-environment-puppeteer": "^6.2.0",
"jest-serializer-html": "^7.1.0",
"lint-staged": "^13.1.0",
Expand Down

0 comments on commit 4106a2e

Please sign in to comment.