@rstest/adapter-rsbuild 0.1.0
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 +23 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +42 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @rstest/adapter-rsbuild
|
|
2
|
+
|
|
3
|
+
Rstest adapter for [Rsbuild](https://rsbuild.rs) configuration. This package allows you to extend your Rstest configuration from Rsbuild config files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rstest/adapter-rsbuild -D
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from '@rstest/core';
|
|
15
|
+
import { withRsbuildConfig } from '@rstest/adapter-rsbuild';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
extends: withRsbuildConfig(),
|
|
19
|
+
// other rstest config options
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
More advanced usage examples can be found in the [Rsbuild integration guide](https://rstest.rs/guide/integration/rsbuild).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
import type { ExtendConfigFn } 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
|
+
export declare function withRsbuildConfig(options?: WithRsbuildConfigOptions): ExtendConfigFn;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { loadConfig, mergeRsbuildConfig } from "@rsbuild/core";
|
|
2
|
+
function withRsbuildConfig(options = {}) {
|
|
3
|
+
return async ()=>{
|
|
4
|
+
const { configPath, modifyRsbuildConfig, environmentName, cwd = process.cwd() } = options;
|
|
5
|
+
const { content: { environments, ...rawBuildConfig }, filePath } = await loadConfig({
|
|
6
|
+
cwd,
|
|
7
|
+
path: configPath
|
|
8
|
+
});
|
|
9
|
+
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
|
+
};
|
|
39
|
+
return rstestConfig;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { withRsbuildConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rstest/adapter-rsbuild",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Rstest adapter for rsbuild configuration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "rslib build",
|
|
19
|
+
"dev": "rslib build --watch",
|
|
20
|
+
"test": "rstest"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"rstest",
|
|
24
|
+
"rsbuild",
|
|
25
|
+
"adapter",
|
|
26
|
+
"configuration"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@rsbuild/core": "*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rslib/core": "^0.19.0",
|
|
34
|
+
"@rsbuild/core": "1.7.1",
|
|
35
|
+
"@rstest/core": "workspace:*",
|
|
36
|
+
"@rstest/tsconfig": "workspace:*"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/web-infra-dev/rstest/issues"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/web-infra-dev/rstest",
|
|
47
|
+
"directory": "packages/adapter-rsbuild"
|
|
48
|
+
}
|
|
49
|
+
}
|