@rstest/adapter-rsbuild 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present ByteDance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Rstest adapter for rsbuild configuration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,11 +14,6 @@
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
- "scripts": {
18
- "build": "rslib build",
19
- "dev": "rslib build --watch",
20
- "test": "rstest"
21
- },
22
17
  "keywords": [
23
18
  "rstest",
24
19
  "rsbuild",
@@ -27,13 +22,14 @@
27
22
  ],
28
23
  "license": "MIT",
29
24
  "peerDependencies": {
30
- "@rsbuild/core": "*"
25
+ "@rsbuild/core": "*",
26
+ "@rstest/core": ">=0.7.7"
31
27
  },
32
28
  "devDependencies": {
33
- "@rslib/core": "^0.19.0",
34
- "@rsbuild/core": "1.7.1",
35
- "@rstest/core": "workspace:*",
36
- "@rstest/tsconfig": "workspace:*"
29
+ "@rsbuild/core": "^2.0.0-beta.6",
30
+ "@rslib/core": "^0.19.6",
31
+ "@rstest/core": "0.8.5",
32
+ "@rstest/tsconfig": "0.0.1"
37
33
  },
38
34
  "publishConfig": {
39
35
  "access": "public"
@@ -45,5 +41,10 @@
45
41
  "type": "git",
46
42
  "url": "https://github.com/web-infra-dev/rstest",
47
43
  "directory": "packages/adapter-rsbuild"
44
+ },
45
+ "scripts": {
46
+ "build": "rslib build",
47
+ "dev": "rslib build --watch",
48
+ "test": "rstest"
48
49
  }
49
- }
50
+ }