Repository navigation
Expand file tree
/
Copy pathvitest.config.js
More file actions
57 lines (54 loc) · 1.92 KB
/
Copy pathvitest.config.js
File metadata and controls
57 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Vitest for `app/javascript/` (importmap + Stimulus).
* Specs live under `test/javascript/`, mirroring `app/javascript/` — not colocated with source.
*
* Bare-path imports resolve by directory, like the aliases in `esbuild.config.js`
* and the `pin_all_from` pins in `config/importmap.rb`. Only vendored packages and
* test stubs need their own entry.
*/
import path from "node:path"
import { fileURLToPath } from "node:url"
import { defineConfig } from "vitest/config"
const repoRoot = path.dirname(fileURLToPath(import.meta.url))
const appJs = path.resolve(repoRoot, "app/javascript")
// Exercise the same vendored editor modules that both browser page types import.
const editorPackages = [
"@codemirror/autocomplete",
"@codemirror/commands",
"@codemirror/lang-javascript",
"@codemirror/lang-json",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/state",
"@codemirror/view",
"@codemirror/streamparser",
"@lezer/common",
"@lezer/highlight",
"@lezer/json",
"@lezer/lr",
"@lezer/javascript",
"@marijn/find-cluster-break",
"crelt",
"style-mod",
"w3c-keyname"
]
export default defineConfig({
test: {
environment: "happy-dom",
include: ["test/javascript/**/*.test.js"],
globals: false,
},
resolve: {
alias: [
...editorPackages.map(name => ({
find: name,
replacement: path.resolve(repoRoot, `vendor/javascript/${name.replaceAll("/", "--")}.js`)
})),
{ find: "@hotwired/stimulus", replacement: path.resolve(repoRoot, "test/javascript/support/stimulus_stub.js") },
{ find: "js-cookie", replacement: path.resolve(repoRoot, "vendor/javascript/js-cookie.js") },
{ find: "party-js", replacement: path.resolve(repoRoot, "vendor/javascript/party-js.js") },
{ find: /^(controllers|utils|stores|api|modules)\/(.*)$/, replacement: `${appJs}/$1/$2` },
{ find: /^(core_runtime|quepid_store)$/, replacement: `${appJs}/$1.js` }
],
},
})