Skip to content

feat(template): add Rstest #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from '@rstest/core';
import { squared } from '../src/index.js';

test('squared', () => {
expect(squared(2)).toBe(4);
expect(squared(12)).toBe(144);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from '@rstest/core';
import { squared } from '../src/index';

test('squared', () => {
expect(squared(2)).toBe(4);
expect(squared(12)).toBe(144);
});
11 changes: 11 additions & 0 deletions packages/create-rslib/fragments/tools/rstest-react-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0",
"jsdom": "^26.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { pluginReact } from '@rsbuild/plugin-react';
import { defineConfig } from '@rstest/core';

export default defineConfig({
testEnvironment: 'jsdom',
setupFiles: ['./rstest.setup.js'],
plugins: [pluginReact()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect } from '@rstest/core';
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';

expect.extend(jestDomMatchers);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from '@rstest/core';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button';

test('The button should have correct background color', async () => {
render(<Button backgroundColor="#ccc" label="Demo Button" />);
const button = screen.getByText('Demo Button');
expect(button).toHaveStyle({
backgroundColor: '#ccc',
});
});
11 changes: 11 additions & 0 deletions packages/create-rslib/fragments/tools/rstest-react-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0",
"jsdom": "^26.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { pluginReact } from '@rsbuild/plugin-react';
import { defineConfig } from '@rstest/core';

export default defineConfig({
testEnvironment: 'jsdom',
setupFiles: ['./rstest.setup.ts'],
plugins: [pluginReact()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect } from '@rstest/core';
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';

expect.extend(jestDomMatchers);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from '@rstest/core';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button';

test('The button should have correct background color', async () => {
render(<Button backgroundColor="#ccc" label="Demo Button" />);
const button = screen.getByText('Demo Button');
expect(button).toHaveStyle({
backgroundColor: '#ccc',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": [".", "../rstest.setup.ts"]
}
12 changes: 12 additions & 0 deletions packages/create-rslib/fragments/tools/rstest-vue-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/vue": "^8.0.0",
"@vue/test-utils": "^2.4.0",
"jsdom": "^26.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@rstest/core';
import { pluginUnpluginVue } from 'rsbuild-plugin-unplugin-vue';

export default defineConfig({
testEnvironment: 'jsdom',
setupFiles: ['./rstest.setup.js'],
plugins: [pluginUnpluginVue()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect } from '@rstest/core';
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';

expect.extend(jestDomMatchers);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, test } from '@rstest/core';
import { render, screen } from '@testing-library/vue';
import Button from '../src/Button.vue';

test('The button should have correct background color', async () => {
render(Button, {
props: {
backgroundColor: '#ccc',
label: 'Demo Button',
},
});
const button = screen.getByText('Demo Button');
expect(button).toHaveStyle({
backgroundColor: '#ccc',
});
});
12 changes: 12 additions & 0 deletions packages/create-rslib/fragments/tools/rstest-vue-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scripts": {
"test": "rstest"
},
"devDependencies": {
"@rstest/core": "^0.1.3",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/vue": "^8.0.0",
"@vue/test-utils": "^2.4.0",
"jsdom": "^26.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@rstest/core';
import { pluginUnpluginVue } from 'rsbuild-plugin-unplugin-vue';

export default defineConfig({
testEnvironment: 'jsdom',
setupFiles: ['./rstest.setup.ts'],
plugins: [pluginUnpluginVue()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect } from '@rstest/core';
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';

expect.extend(jestDomMatchers);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect, test } from '@rstest/core';
import { render, screen } from '@testing-library/vue';
import Button from '../src/Button.vue';

test('The button should have correct background color', async () => {
render(Button, {
props: {
backgroundColor: '#ccc',
label: 'Demo Button',
},
});
const button = screen.getByText('Demo Button');
expect(button).toHaveStyle({
backgroundColor: '#ccc',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": [".", "../rstest.setup.ts"]
}
50 changes: 47 additions & 3 deletions packages/create-rslib/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export const composeTemplateName = ({
lang,
}: {
template: string;
tools?: Record<string, string>;
tools?: string[];
lang: Lang;
}) => {
return `[${template}]-[${(tools ? Object.keys(tools) : []).sort()}]-${lang}`;
return `[${template}]-[${(tools ? tools.sort() : []).join(',')}]-${lang}`;
};

export function genTemplate({
Expand All @@ -43,7 +43,7 @@ export function genTemplate({
const toolKeys = tools ? Object.keys(tools) : [];
const target = path.resolve(
__dirname,
`../template-${composeTemplateName({ template, tools, lang })}`,
`../template-${composeTemplateName({ template, tools: toolKeys, lang })}`,
);
fs.rmSync(target, { recursive: true, force: true });
const srcBase = getBase({ template, lang });
Expand Down Expand Up @@ -77,11 +77,15 @@ export const TEMPLATES: Template[] = [
{ template: 'node-dual', lang: 'ts' },
{ template: 'node-dual', lang: 'js', tools: { vitest: 'vitest-node-js' } },
{ template: 'node-dual', lang: 'ts', tools: { vitest: 'vitest-node-ts' } },
{ template: 'node-dual', lang: 'js', tools: { rstest: 'rstest-node-js' } },
{ template: 'node-dual', lang: 'ts', tools: { rstest: 'rstest-node-ts' } },
// node-esm
{ template: 'node-esm', lang: 'js' },
{ template: 'node-esm', lang: 'ts' },
{ template: 'node-esm', lang: 'js', tools: { vitest: 'vitest-node-js' } },
{ template: 'node-esm', lang: 'ts', tools: { vitest: 'vitest-node-ts' } },
{ template: 'node-esm', lang: 'js', tools: { rstest: 'rstest-node-js' } },
{ template: 'node-esm', lang: 'ts', tools: { rstest: 'rstest-node-ts' } },
// react-js
{
template: 'react',
Expand All @@ -97,11 +101,21 @@ export const TEMPLATES: Template[] = [
lang: 'js',
tools: { vitest: 'vitest-react-js' },
},
{
template: 'react',
lang: 'js',
tools: { rstest: 'rstest-react-js' },
},
{
template: 'react',
lang: 'js',
tools: { storybook: 'storybook-react-js', vitest: 'vitest-react-js' },
},
{
template: 'react',
lang: 'js',
tools: { storybook: 'storybook-react-js', rstest: 'rstest-react-js' },
},
// react-ts
{
template: 'react',
Expand All @@ -117,11 +131,21 @@ export const TEMPLATES: Template[] = [
lang: 'ts',
tools: { vitest: 'vitest-react-ts' },
},
{
template: 'react',
lang: 'ts',
tools: { rstest: 'rstest-react-ts' },
},
{
template: 'react',
lang: 'ts',
tools: { storybook: 'storybook-react-ts', vitest: 'vitest-react-ts' },
},
{
template: 'react',
lang: 'ts',
tools: { storybook: 'storybook-react-ts', rstest: 'rstest-react-ts' },
},
// vue-js
{
template: 'vue',
Expand All @@ -137,11 +161,21 @@ export const TEMPLATES: Template[] = [
lang: 'js',
tools: { vitest: 'vitest-vue-js' },
},
{
template: 'vue',
lang: 'js',
tools: { rstest: 'rstest-vue-js' },
},
{
template: 'vue',
lang: 'js',
tools: { storybook: 'storybook-vue-js', vitest: 'vitest-vue-js' },
},
{
template: 'vue',
lang: 'js',
tools: { storybook: 'storybook-vue-js', rstest: 'rstest-vue-js' },
},
// vue-ts
{
template: 'vue',
Expand All @@ -157,9 +191,19 @@ export const TEMPLATES: Template[] = [
lang: 'ts',
tools: { vitest: 'vitest-vue-ts' },
},
{
template: 'vue',
lang: 'ts',
tools: { rstest: 'rstest-vue-ts' },
},
{
template: 'vue',
lang: 'ts',
tools: { storybook: 'storybook-vue-ts', vitest: 'vitest-vue-ts' },
},
{
template: 'vue',
lang: 'ts',
tools: { storybook: 'storybook-vue-ts', rstest: 'rstest-vue-ts' },
},
] as const;
Loading
Loading