You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aea2b87
Browse filesBrowse the repository at this point in the historyBrowse files
- Pass an array of configuration objects. If a preset is a function, call it first and pass the returned object.
42
+
- Call at most once per configuration load. An empty array still counts as a call.
43
+
- Shared configurations are applied from left to right, followed by the project's `define.*()` settings, regardless of call order.
44
+
45
+
See [Shared configurations](./configuration#shared-configurations) for nested inheritance, merge rules, and examples.
46
+
47
+
### `RstackConfig`
48
+
49
+
Use this type to define a shared configuration. All fields are optional: `app`, `lib`, `doc`, `test`, `lint`, `fmt`, and `staged` accept the same values as their corresponding `define.*()` APIs. Add `extends`, typed as `readonly RstackConfig[]`, to inherit other shared configurations.
-`cwd`: the directory used to search for a configuration file and resolve relative configuration file paths. Defaults to the current working directory.
79
+
-`configFilePath`: a relative or absolute configuration file path. If omitted, uses the CLI's `--config` path when set; otherwise, searches for the [default configuration file names](./configuration#configuration-file) in `cwd`.
80
+
81
+
The returned object contains:
82
+
83
+
-`configs`: tool configuration definitions that include both shared and project settings. Tools with no configuration are omitted.
84
+
-`filePath`: the loaded configuration file's path, or `null` if no file was found.
85
+
-`dependencies`: the configuration's dependencies, as reported by the loader.
86
+
87
+
The loader leaves configuration functions unevaluated. It may also return an async function for a tool whose inputs were all objects, so those objects can be merged when the tool is needed.
88
+
89
+
When using the result, resolve each definition with the parameters its tool expects, then follow that tool's setup and execution steps. Rstack's automatic test inheritance and formatting normalization still need to run at that stage. A `staged` function is a task generator: call it with the staged file names when running tasks.
90
+
91
+
`rstack/config` also exports the `Configs`, `LoadedRstackConfig`, and `LoadRstackConfigOptions` types.
92
+
28
93
## Re-exports
29
94
30
95
The tool-specific subpaths below re-export the public APIs from their corresponding core packages. Using these entry points keeps imports unified and APIs aligned with the tool versions integrated by Rstack CLI.
Copy file name to clipboardExpand all lines: website/docs/en/guide/testing.mdx
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,48 @@ define.test({
107
107
108
108
For multiple projects, setting `extends` on the root `define.test()` configuration disables automatic inheritance for every project. Setting it on an inline project disables inheritance only for that project.
109
109
110
+
### Shared test configurations
111
+
112
+
A [shared configuration](./configuration#shared-configurations) can provide both build and test settings. Rstack combines these with the project's settings before deciding whether tests should inherit the build configuration.
113
+
114
+
First, Rstack merges the test settings with `mergeRstestConfig`. It then checks `extends` and `projects` in the merged result. Tests that need automatic inheritance use the merged App configuration, or the merged Lib configuration if no App configuration is defined.
115
+
116
+
`define.extends()` and Rstest's `test.extends` serve different purposes: the former shares settings across tools; the latter controls Rstest's own configuration inheritance.
117
+
118
+
```ts title="shared.ts"
119
+
importtype { RstackConfig } from'rstack';
120
+
121
+
exportconst sharedConfig:RstackConfig= {
122
+
app: {
123
+
resolve: {
124
+
alias: {
125
+
'@': './src',
126
+
},
127
+
},
128
+
},
129
+
test: {
130
+
retry: 2,
131
+
},
132
+
};
133
+
```
134
+
135
+
```ts title="rstack.config.ts"
136
+
import { define } from'rstack';
137
+
import { sharedConfig } from'./shared.ts';
138
+
139
+
define.extends([sharedConfig]);
140
+
141
+
define.test({
142
+
testEnvironment: 'happy-dom',
143
+
});
144
+
```
145
+
146
+
Tests run in happy-dom with `retry: 2` and inherit the shared App configuration's `@` alias. There is no need to call `define.app()` in the project.
147
+
148
+
To disable automatic inheritance, set `extends` explicitly in the test configuration. This also works in a shared configuration: if the merged test settings contain `extends`, even as `extends: undefined`, automatic inheritance is disabled.
149
+
150
+
For multiple projects, Rstack checks the merged inline projects individually. External projects specified by strings still load their own configurations. If no project needs automatic inheritance, Rstack skips the App and Lib configuration functions.
151
+
110
152
## Multiple projects
111
153
112
154
Set Rstest's [`projects`](https://rstest.rs/config/test/projects) option to run multiple test configurations together. Entries can be inline projects or strings that Rstest resolves as external projects.
0 commit comments