import Chai from 'chai'
import ChaiArrays from 'chai-arrays'
import ChaiAsPromised from 'chai-as-promised'
import ChaiEach from 'chai-each'
import Sinon from 'sinon'
import ChaiSinon from 'sinon-chai'
import * as SnapshotPlugin from 'mocha-chai-jest-snapshot'
const { jestSnapshotPlugin } = SnapshotPlugin
Chai.use(ChaiArrays)
Chai.use(ChaiEach)
Chai.use(ChaiSinon)
Chai.use(SnapshotPlugin.jestSnapshotPlugin())
Chai.use(ChaiAsPromised) // must be last
global.sinon = Sinon
global.expect = Chai.expect
Error.stackTraceLimit = 50
and jest.config.cjs:
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
module.exports = {
// Run tests from one or more projects
projects: [
{
displayName: "tests",
// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['./tests/setupFilesAfterEnv.js'],
testMatch: ["<rootDir>/tests/**/*.test.[tj]s?(x)"],
testPathIgnorePatterns: ["tests\/store", "tests\/.*\/.*Store.*"],
},
{
displayName: "dbtests",
// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['./tests/setupFilesAfterEnv.js'],
testMatch: ["<rootDir>/tests/store/*.test.[tj]s?(x)", "<rootDir>/tests/*/.*Store*.test.[tj]s?(x)"],
},
// {
// displayName: "lint",
// runner: "jest-runner-eslint",
// testMatch: ["<rootDir>/{src,tests}/**/*.{js,ts}"],
// },
],
//
// A list of paths to directories that Jest should use to search for files in
roots: [
'tests',
// 'built',
],
// The glob patterns Jest uses to detect test files
testMatch: [
"**/tests/**/*.test.[tj]s?(x)",
],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ['./tests/setupFilesAfterEnv.js'],
// The test environment that will be used for testing
testEnvironment: "node",
// Indicates whether each individual test should be reported during the run
verbose: true,
// The maximum amount of workers used to run your tests. Can be specified as % or a number.
// E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number.
// maxWorkers: 2 will use a maximum of 2 workers.
maxWorkers: "30%",
}
Could not get this to work; it gives the error
ReferenceError: before is not defined
.It traces back to these lines (in the built version)
Those don't seem to be globals delivered by Jest.
My jest setupFilesAfterEnv.js:
and jest.config.cjs: