Skip to content

Commit

Permalink
test: add e2e cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Aug 18, 2024
1 parent e1a9b88 commit c6526e9
Show file tree
Hide file tree
Showing 16 changed files with 1,431 additions and 115 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@playwright/test": "^1.45.3",
"@rsbuild/core": "^1.0.1-beta.11",
"@rsbuild/core": "^1.0.1-beta.14",
"@rsbuild/plugin-vue2": "^1.0.1-beta.14",
"@types/node": "^20.14.13",
"nano-staged": "^0.8.0",
"playwright": "^1.45.3",
"simple-git-hooks": "^2.11.1",
"tsup": "^8.2.3",
"typescript": "^5.5.4"
"typescript": "^5.5.4",
"vue": "^2.7.14"
},
"peerDependencies": {
"@rsbuild/core": "1.x || ^1.0.1-beta.0"
Expand Down
1,275 changes: 1,207 additions & 68 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

44 changes: 0 additions & 44 deletions test/basic/index.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/basic/src/index.js

This file was deleted.

22 changes: 22 additions & 0 deletions test/jsx-basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild, loadConfig } from '@rsbuild/core';

const __dirname = dirname(fileURLToPath(import.meta.url));

test('should build basic Vue jsx correctly', async ({ page }) => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: (await loadConfig({ cwd: __dirname })).content,
});

await rsbuild.build();
const { server, urls } = await rsbuild.preview();

await page.goto(urls[0]);
const button1 = page.locator('#button1');
await expect(button1).toHaveText('A: 0');

await server.close();
});
18 changes: 18 additions & 0 deletions test/jsx-basic/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginVue2 } from '@rsbuild/plugin-vue2';
import { pluginVue2Jsx } from '../../dist';
import { getRandomPort } from '../helper';

export default defineConfig({
plugins: [
pluginVue2(),
pluginVue2Jsx(),
pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
],
server: {
port: getRandomPort(),
},
});
19 changes: 19 additions & 0 deletions test/jsx-basic/src/A.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineComponent } from 'vue';

export default defineComponent({
name: 'Test',

data() {
return {
count: 0,
};
},

render() {
return (
<button id="button1" type="button" onClick={() => this.count++}>
A: {this.count}
</button>
);
},
});
7 changes: 7 additions & 0 deletions test/jsx-basic/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue';
import A from './A';

new Vue({
el: '#root',
render: (h) => h(A),
});
25 changes: 25 additions & 0 deletions test/sfc-lang-jsx/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild, loadConfig } from '@rsbuild/core';

const __dirname = dirname(fileURLToPath(import.meta.url));

test('should build Vue sfc with lang="jsx" correctly', async ({ page }) => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: (await loadConfig({ cwd: __dirname })).content,
});

await rsbuild.build();
const { server, urls } = await rsbuild.preview();

await page.goto(urls[0]);
const button = page.locator('#button');
await expect(button).toHaveText('0');

const foo = page.locator('#foo');
await expect(foo).toHaveText('Foo');

await server.close();
});
18 changes: 18 additions & 0 deletions test/sfc-lang-jsx/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginVue2 } from '@rsbuild/plugin-vue2';
import { pluginVue2Jsx } from '@rsbuild/plugin-vue2-jsx';
import { getRandomPort } from '../helper';

export default defineConfig({
plugins: [
pluginVue2(),
pluginVue2Jsx(),
pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
],
server: {
port: getRandomPort(),
},
});
27 changes: 27 additions & 0 deletions test/sfc-lang-jsx/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div>
<button id="button" type="button" @click="count++">{{ count }}</button>
<Foo />
</div>
</template>

<script lang="jsx">
import { ref } from 'vue';
const Foo = {
render() {
return <div id="foo">Foo</div>;
},
};
export default {
components: {
Foo,
},
setup() {
const count = ref(0);
return { count };
},
};
</script>
7 changes: 7 additions & 0 deletions test/sfc-lang-jsx/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue';
import App from './App.vue';

new Vue({
el: '#root',
render: (h) => h(App),
});
25 changes: 25 additions & 0 deletions test/sfc-lang-tsx/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild, loadConfig } from '@rsbuild/core';

const __dirname = dirname(fileURLToPath(import.meta.url));

test('should build Vue sfc with lang="tsx" correctly', async ({ page }) => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: (await loadConfig({ cwd: __dirname })).content,
});

await rsbuild.build();
const { server, urls } = await rsbuild.preview();

await page.goto(urls[0]);
const button = page.locator('#button');
await expect(button).toHaveText('0');

const foo = page.locator('#foo');
await expect(foo).toHaveText('Foo');

await server.close();
});
18 changes: 18 additions & 0 deletions test/sfc-lang-tsx/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from '@rsbuild/core';
import { pluginBabel } from '@rsbuild/plugin-babel';
import { pluginVue2 } from '@rsbuild/plugin-vue2';
import { pluginVue2Jsx } from '@rsbuild/plugin-vue2-jsx';
import { getRandomPort } from '../helper';

export default defineConfig({
plugins: [
pluginVue2(),
pluginVue2Jsx(),
pluginBabel({
include: /\.(?:jsx|tsx)$/,
}),
],
server: {
port: getRandomPort(),
},
});
27 changes: 27 additions & 0 deletions test/sfc-lang-tsx/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div>
<button id="button" type="button" @click="count++">{{ count }}</button>
<Foo />
</div>
</template>

<script lang="tsx">
import { ref } from 'vue';
const Foo = {
render() {
return <div id="foo">Foo</div>;
},
};
export default {
components: {
Foo,
},
setup() {
const count = ref<number>(0);
return { count };
},
};
</script>
7 changes: 7 additions & 0 deletions test/sfc-lang-tsx/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue';
import App from './App.vue';

new Vue({
el: '#root',
render: (h) => h(App),
});

0 comments on commit c6526e9

Please sign in to comment.