Skip to content

Commit

Permalink
Update jest configuration to include webpacker dir
Browse files Browse the repository at this point in the history
This allows the test environment to correctly resolve import of
services in controller ie: `import OptionValueNamer from
"js/services/option_value_namer";`

The added benefit is we can now import package to be tested directly
without having to specify the whole relative path ie in test file you
can do : `import variant_controller from "controllers/variant_controller";`
  • Loading branch information
rioug committed Oct 14, 2024
1 parent 6ff9650 commit 9403052
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ module.exports = {
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],
moduleDirectories: ["node_modules", "app/webpacker"],

// An array of file extensions your modules use
// moduleFileExtensions: [
Expand Down Expand Up @@ -157,9 +155,7 @@ module.exports = {
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
"testRegex": [
"spec/javascripts/.*_test\\.js"
],
testRegex: ["spec/javascripts/.*_test\\.js"],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
Expand All @@ -177,9 +173,7 @@ module.exports = {
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
"transformIgnorePatterns": [
"/node_modules/(?!(stimulus)/)"
]
transformIgnorePatterns: ["/node_modules/(?!(stimulus)/)"],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down

0 comments on commit 9403052

Please sign in to comment.