@bleedingdev/modern-js-adapter-rstest 3.2.0-ultramodern.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/LICENSE +21 -0
- package/dist/index.js +36 -0
- package/dist/types/index.d.ts +12 -0
- package/package.json +48 -0
- package/rslib.config.mts +12 -0
- package/rstest.config.mts +11 -0
- package/src/index.ts +62 -0
- package/tests/index.test.ts +46 -0
- package/tsconfig.json +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
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/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function withModernConfig(options = {}) {
|
|
2
|
+
return async ()=>{
|
|
3
|
+
const { loadEnv } = await import("@rsbuild/core");
|
|
4
|
+
const cwd = options.cwd || process.cwd();
|
|
5
|
+
loadEnv({
|
|
6
|
+
cwd,
|
|
7
|
+
mode: process.env.MODERN_ENV || process.env.NODE_ENV,
|
|
8
|
+
prefixes: [
|
|
9
|
+
'MODERN_'
|
|
10
|
+
]
|
|
11
|
+
});
|
|
12
|
+
const { resolveModernRsbuildConfig } = await import("@modern-js/app-tools");
|
|
13
|
+
const { rsbuildConfig } = await resolveModernRsbuildConfig({
|
|
14
|
+
...options,
|
|
15
|
+
command: 'rstest',
|
|
16
|
+
modifyModernConfig: async (config)=>{
|
|
17
|
+
if (config.server?.rsc) {
|
|
18
|
+
console.warn('RSC is not fully supported in rstest environment, some features may not work as expected.\n');
|
|
19
|
+
config.server.rsc = false;
|
|
20
|
+
}
|
|
21
|
+
config.plugins = config.plugins?.filter((plugin)=>'@modern-js/plugin-bff' !== plugin.name);
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
}).catch((error)=>{
|
|
25
|
+
if (error instanceof Error) error.message = `Error loading Modern.js config${options.cwd ? ` in ${options.cwd}` : ''}: ${error.message}`;
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
const { toRstestConfig } = await import("@rstest/adapter-rsbuild");
|
|
29
|
+
const rstestExtendConfig = toRstestConfig({
|
|
30
|
+
rsbuildConfig,
|
|
31
|
+
environmentName: options.environmentName || 'client'
|
|
32
|
+
});
|
|
33
|
+
return rstestExtendConfig;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export { withModernConfig };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ResolveModernRsbuildConfigOptions } from '@modern-js/app-tools';
|
|
2
|
+
import type { ExtendConfigFn } from '@rstest/core';
|
|
3
|
+
type AdapterInitOptions = Pick<ResolveModernRsbuildConfigOptions, 'cwd' | 'configPath'> & {
|
|
4
|
+
/**
|
|
5
|
+
* The environment name in `environments` field to use, will be merged with the common config.
|
|
6
|
+
* Set to a string to use the environment config with matching name.
|
|
7
|
+
* @default 'client'
|
|
8
|
+
*/
|
|
9
|
+
environmentName?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function withModernConfig(options?: AdapterInitOptions): ExtendConfigFn;
|
|
12
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bleedingdev/modern-js-adapter-rstest",
|
|
3
|
+
"description": "Modern.js adapter to run tests via Rstest.",
|
|
4
|
+
"homepage": "https://github.com/BleedingDev/ultramodern.js#readme",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/BleedingDev/ultramodern.js/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/BleedingDev/ultramodern.js.git",
|
|
11
|
+
"directory": "packages/cli/adapter-rstest"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"version": "3.2.0-ultramodern.0",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@rstest/adapter-rsbuild": "^0.10.0",
|
|
26
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@rsbuild/core": "2.0.6",
|
|
30
|
+
"@rslib/core": "0.21.5",
|
|
31
|
+
"@rstest/core": "0.10.0",
|
|
32
|
+
"@types/node": "^25.8.0",
|
|
33
|
+
"@typescript/native-preview": "7.0.0-dev.20260516.1",
|
|
34
|
+
"@scripts/rstest-config": "2.66.0",
|
|
35
|
+
"@modern-js/tsconfig": "npm:@bleedingdev/modern-js-tsconfig@3.2.0-ultramodern.0",
|
|
36
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.0"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"registry": "https://registry.npmjs.org/",
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rslib build && pnpm -w tsgo:dts \"$PWD\"",
|
|
45
|
+
"dev": "rslib build --watch",
|
|
46
|
+
"test": "rstest"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/rslib.config.mts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ResolveModernRsbuildConfigOptions } from '@modern-js/app-tools';
|
|
2
|
+
import type { ExtendConfigFn } from '@rstest/core';
|
|
3
|
+
|
|
4
|
+
type AdapterInitOptions = Pick<
|
|
5
|
+
ResolveModernRsbuildConfigOptions,
|
|
6
|
+
'cwd' | 'configPath'
|
|
7
|
+
> & {
|
|
8
|
+
/**
|
|
9
|
+
* The environment name in `environments` field to use, will be merged with the common config.
|
|
10
|
+
* Set to a string to use the environment config with matching name.
|
|
11
|
+
* @default 'client'
|
|
12
|
+
*/
|
|
13
|
+
environmentName?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function withModernConfig(
|
|
17
|
+
options: AdapterInitOptions = {},
|
|
18
|
+
): ExtendConfigFn {
|
|
19
|
+
return async () => {
|
|
20
|
+
const { loadEnv } = await import('@rsbuild/core');
|
|
21
|
+
const cwd = options.cwd || process.cwd();
|
|
22
|
+
loadEnv({
|
|
23
|
+
cwd,
|
|
24
|
+
mode: process.env.MODERN_ENV || process.env.NODE_ENV,
|
|
25
|
+
prefixes: ['MODERN_'],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { resolveModernRsbuildConfig } = await import('@modern-js/app-tools');
|
|
29
|
+
const { rsbuildConfig } = await resolveModernRsbuildConfig({
|
|
30
|
+
...options,
|
|
31
|
+
command: 'rstest',
|
|
32
|
+
modifyModernConfig: async config => {
|
|
33
|
+
if (config.server?.rsc) {
|
|
34
|
+
console.warn(
|
|
35
|
+
'RSC is not fully supported in rstest environment, some features may not work as expected.\n',
|
|
36
|
+
);
|
|
37
|
+
config.server.rsc = false;
|
|
38
|
+
}
|
|
39
|
+
// remove unsupported plugins in rstest environment, such as bff plugin, which may cause errors when running rstest.
|
|
40
|
+
config.plugins = config.plugins?.filter(
|
|
41
|
+
plugin => plugin.name !== '@modern-js/plugin-bff',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return config;
|
|
45
|
+
},
|
|
46
|
+
}).catch((error: unknown) => {
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
error.message = `Error loading Modern.js config${options.cwd ? ` in ${options.cwd}` : ''}: ${error.message}`;
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const { toRstestConfig } = await import('@rstest/adapter-rsbuild');
|
|
54
|
+
|
|
55
|
+
const rstestExtendConfig = toRstestConfig({
|
|
56
|
+
rsbuildConfig,
|
|
57
|
+
environmentName: options.environmentName || 'client',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return rstestExtendConfig;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { resolveModernRsbuildConfig } from '@modern-js/app-tools';
|
|
2
|
+
import { afterEach, describe, expect, rstest, test } from '@rstest/core';
|
|
3
|
+
import { withModernConfig } from '../src';
|
|
4
|
+
|
|
5
|
+
rstest.mock('@modern-js/app-tools', () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
resolveModernRsbuildConfig: rstest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('withModernConfig', () => {
|
|
11
|
+
const mockResolveModernRsbuildConfig = rstest.mocked(
|
|
12
|
+
resolveModernRsbuildConfig,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
rstest.resetAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should resolve modern rsbuild config with rstest command', async () => {
|
|
20
|
+
mockResolveModernRsbuildConfig.mockResolvedValue({
|
|
21
|
+
rsbuildConfig: {
|
|
22
|
+
root: '/app',
|
|
23
|
+
output: {
|
|
24
|
+
target: 'node',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const extend = withModernConfig({
|
|
30
|
+
cwd: '/app',
|
|
31
|
+
configPath: 'custom.modern.config.ts',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const config = await extend({});
|
|
35
|
+
|
|
36
|
+
expect(mockResolveModernRsbuildConfig).toBeCalledTimes(1);
|
|
37
|
+
expect(mockResolveModernRsbuildConfig).toBeCalledWith({
|
|
38
|
+
cwd: '/app',
|
|
39
|
+
configPath: 'custom.modern.config.ts',
|
|
40
|
+
command: 'rstest',
|
|
41
|
+
modifyModernConfig: expect.any(Function),
|
|
42
|
+
});
|
|
43
|
+
expect(config.testEnvironment).toBe('node');
|
|
44
|
+
expect(config.root).toBe('/app');
|
|
45
|
+
});
|
|
46
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@modern-js/tsconfig/base",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"ignoreDeprecations": "5.0",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"noUnusedLocals": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"moduleResolution": "Bundler"
|
|
11
|
+
},
|
|
12
|
+
"include": ["src"]
|
|
13
|
+
}
|