@rstest/adapter-rsbuild 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,8 @@ npm install @rstest/adapter-rsbuild -D
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### `withRsbuildConfig`
14
+
13
15
  ```ts
14
16
  import { defineConfig } from '@rstest/core';
15
17
  import { withRsbuildConfig } from '@rstest/adapter-rsbuild';
@@ -20,4 +22,37 @@ export default defineConfig({
20
22
  });
21
23
  ```
22
24
 
25
+ Automatically loads Rsbuild config from the current working directory and converts it to Rstest config.
26
+
23
27
  More advanced usage examples can be found in the [Rsbuild integration guide](https://rstest.rs/guide/integration/rsbuild).
28
+
29
+ ### `toRstestConfig`
30
+
31
+ You can also use `toRstestConfig` directly when you already have an Rsbuild config object.
32
+
33
+ ```ts
34
+ import { loadConfig } from '@rsbuild/core';
35
+ import { toRstestConfig } from '@rstest/adapter-rsbuild';
36
+
37
+ const { content: rsbuildConfig } = await loadConfig({
38
+ cwd: process.cwd(),
39
+ });
40
+
41
+ const rstestConfig = toRstestConfig({
42
+ rsbuildConfig,
43
+ environmentName: 'node',
44
+ modifyRsbuildConfig: (config) => ({
45
+ ...config,
46
+ output: {
47
+ ...config.output,
48
+ target: 'node',
49
+ },
50
+ }),
51
+ });
52
+ ```
53
+
54
+ ### Options
55
+
56
+ - `rsbuildConfig`: Required. The Rsbuild config object to convert.
57
+ - `environmentName`: Optional. Name of the config in `environments` to merge with the base config.
58
+ - `modifyRsbuildConfig`: Optional. Hook to modify merged Rsbuild config before conversion.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type RsbuildConfig } from '@rsbuild/core';
2
2
  import type { ExtendConfigFn } from '@rstest/core';
3
+ import { toRstestConfig } from './toRstestConfig';
3
4
  export interface WithRsbuildConfigOptions {
4
5
  /**
5
6
  * `cwd` passed to loadConfig of Rsbuild
@@ -23,3 +24,4 @@ export interface WithRsbuildConfigOptions {
23
24
  modifyRsbuildConfig?: (buildConfig: RsbuildConfig) => RsbuildConfig;
24
25
  }
25
26
  export declare function withRsbuildConfig(options?: WithRsbuildConfigOptions): ExtendConfigFn;
27
+ export { toRstestConfig };
package/dist/index.js CHANGED
@@ -1,42 +1,59 @@
1
1
  import { loadConfig, mergeRsbuildConfig } from "@rsbuild/core";
2
+ function toRstestConfig({ environmentName, rsbuildConfig: rawRsbuildConfig, modifyRsbuildConfig }) {
3
+ const { environments, ...rawBuildConfig } = rawRsbuildConfig;
4
+ const environmentConfig = environmentName ? environments?.[environmentName] : void 0;
5
+ const rsbuildConfig = environmentConfig ? mergeRsbuildConfig(rawBuildConfig, environmentConfig) : rawBuildConfig;
6
+ const finalBuildConfig = modifyRsbuildConfig ? modifyRsbuildConfig(rsbuildConfig) : rsbuildConfig;
7
+ const { rspack, swc, bundlerChain } = finalBuildConfig.tools || {};
8
+ const { cssModules, target, module } = finalBuildConfig.output || {};
9
+ const { decorators, define, include, exclude, tsconfigPath } = finalBuildConfig.source || {};
10
+ return {
11
+ root: finalBuildConfig.root,
12
+ name: environmentName,
13
+ plugins: [
14
+ ...finalBuildConfig.plugins || [],
15
+ {
16
+ name: 'remove-useless-plugins',
17
+ remove: [
18
+ 'rsbuild:type-check'
19
+ ],
20
+ setup: ()=>{}
21
+ }
22
+ ],
23
+ source: {
24
+ decorators,
25
+ define,
26
+ include,
27
+ exclude,
28
+ tsconfigPath
29
+ },
30
+ resolve: finalBuildConfig.resolve,
31
+ output: {
32
+ cssModules,
33
+ module
34
+ },
35
+ tools: {
36
+ rspack,
37
+ swc,
38
+ bundlerChain
39
+ },
40
+ testEnvironment: 'node' === target ? 'node' : 'happy-dom'
41
+ };
42
+ }
2
43
  function withRsbuildConfig(options = {}) {
3
44
  return async ()=>{
4
45
  const { configPath, modifyRsbuildConfig, environmentName, cwd = process.cwd() } = options;
5
- const { content: { environments, ...rawBuildConfig }, filePath } = await loadConfig({
46
+ const { content: rsbuildConfig, filePath } = await loadConfig({
6
47
  cwd,
7
48
  path: configPath
8
49
  });
9
50
  if (!filePath) return {};
10
- const environmentConfig = environmentName ? environments?.[environmentName] : void 0;
11
- const rsbuildConfig = environmentConfig ? mergeRsbuildConfig(rawBuildConfig, environmentConfig) : rawBuildConfig;
12
- const finalBuildConfig = modifyRsbuildConfig ? modifyRsbuildConfig(rsbuildConfig) : rsbuildConfig;
13
- const { rspack, swc, bundlerChain } = finalBuildConfig.tools || {};
14
- const { cssModules, target, module } = finalBuildConfig.output || {};
15
- const { decorators, define, include, exclude, tsconfigPath } = finalBuildConfig.source || {};
16
- const rstestConfig = {
17
- root: finalBuildConfig.root,
18
- name: environmentName,
19
- plugins: finalBuildConfig.plugins,
20
- source: {
21
- decorators,
22
- define,
23
- include,
24
- exclude,
25
- tsconfigPath
26
- },
27
- resolve: finalBuildConfig.resolve,
28
- output: {
29
- cssModules,
30
- module
31
- },
32
- tools: {
33
- rspack,
34
- swc,
35
- bundlerChain
36
- },
37
- testEnvironment: 'node' === target ? 'node' : 'happy-dom'
38
- };
51
+ const rstestConfig = toRstestConfig({
52
+ environmentName,
53
+ rsbuildConfig,
54
+ modifyRsbuildConfig
55
+ });
39
56
  return rstestConfig;
40
57
  };
41
58
  }
42
- export { withRsbuildConfig };
59
+ export { toRstestConfig, withRsbuildConfig };
@@ -0,0 +1,32 @@
1
+ import { type RsbuildConfig } from '@rsbuild/core';
2
+ import type { ExtendConfig } from '@rstest/core';
3
+ export interface WithRsbuildConfigOptions {
4
+ /**
5
+ * `cwd` passed to loadConfig of Rsbuild
6
+ * @default process.cwd()
7
+ */
8
+ cwd?: string;
9
+ /**
10
+ * Path to rsbuild config file
11
+ * @default './rsbuild.config.ts'
12
+ */
13
+ configPath?: string;
14
+ /**
15
+ * The environment name in `environments` field to use, will be merged with the common config.
16
+ * Set to a string to use the environment config with matching name.
17
+ * @default undefined
18
+ */
19
+ environmentName?: string;
20
+ /**
21
+ * Modify rsbuild config before converting to rstest config
22
+ */
23
+ modifyRsbuildConfig?: (buildConfig: RsbuildConfig) => RsbuildConfig;
24
+ }
25
+ /**
26
+ * Convert rsbuild config to rstest config
27
+ */
28
+ export declare function toRstestConfig({ environmentName, rsbuildConfig: rawRsbuildConfig, modifyRsbuildConfig, }: {
29
+ environmentName?: string;
30
+ rsbuildConfig: RsbuildConfig;
31
+ modifyRsbuildConfig?: (buildConfig: RsbuildConfig) => RsbuildConfig;
32
+ }): ExtendConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/adapter-rsbuild",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Rstest adapter for rsbuild configuration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,9 +26,9 @@
26
26
  "@rstest/core": ">=0.7.7"
27
27
  },
28
28
  "devDependencies": {
29
- "@rslib/core": "^0.19.0",
30
- "@rsbuild/core": "1.7.2",
31
- "@rstest/core": "0.8.0",
29
+ "@rsbuild/core": "^2.0.0-beta.6",
30
+ "@rslib/core": "^0.19.6",
31
+ "@rstest/core": "0.8.5",
32
32
  "@rstest/tsconfig": "0.0.1"
33
33
  },
34
34
  "publishConfig": {