Skip to content

Commit 3dd5ad3

Browse files
committed
feat: add config tests
1 parent b195fc3 commit 3dd5ad3

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

packages/e2e-tests/configfile-custom/__tests__/configfile-custom.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
it('should load config and work', async () => {
1+
import { editViteConfig } from 'testUtils';
2+
3+
it('should load default config and work', async () => {
4+
expect(await page.textContent('h1')).toMatch('Hello world!');
5+
expect(await page.textContent('#test-child')).toBe('test-child');
6+
expect(await page.textContent('#dependency-import')).toBe('dependency-import');
7+
});
8+
9+
it('should load custom mjs config and work', async () => {
10+
await editViteConfig((c) =>
11+
c.replace('svelte()', `svelte({configFile:'svelte.config.custom.cjs'})`)
12+
);
213
expect(await page.textContent('h1')).toMatch('Hello world!');
314
expect(await page.textContent('#test-child')).toBe('test-child');
415
expect(await page.textContent('#dependency-import')).toBe('dependency-import');

packages/e2e-tests/configfile-esm/__tests__/configfile-esm.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
it('should load config and work', async () => {
1+
import { editViteConfig } from 'testUtils';
2+
3+
it('should load default config and work', async () => {
4+
expect(await page.textContent('h1')).toMatch('Hello world!');
5+
expect(await page.textContent('#test-child')).toBe('test-child');
6+
expect(await page.textContent('#dependency-import')).toBe('dependency-import');
7+
});
8+
9+
it('should load custom cjs config and work', async () => {
10+
await editViteConfig((c) =>
11+
c.replace('svelte()', `svelte({configFile:'svelte.config.custom.cjs'})`)
12+
);
213
expect(await page.textContent('h1')).toMatch('Hello world!');
314
expect(await page.textContent('#test-child')).toBe('test-child');
415
expect(await page.textContent('#dependency-import')).toBe('dependency-import');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const sveltePreprocess = require('svelte-preprocess');
2+
3+
module.exports = {
4+
preprocess: sveltePreprocess()
5+
};

packages/e2e-tests/hmr/__tests__/hmr.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
getColor,
1010
editFile,
1111
addFile,
12-
removeFile
12+
removeFile,
13+
editViteConfig
1314
} from '../../testUtils';
1415

1516
test('should render App', async () => {
@@ -123,10 +124,7 @@ if (!isBuild) {
123124
});
124125

125126
test('should work with emitCss: false', async () => {
126-
await editFile('vite.config.js', (c) => c.replace('svelte()', 'svelte({emitCss:false})'));
127-
await sleep(isWin ? 1000 : 500); // editing vite config restarts server, give it some time
128-
await page.goto(viteTestUrl, { waitUntil: 'networkidle' });
129-
await sleep(50);
127+
await editViteConfig((c) => c.replace('svelte()', 'svelte({emitCss:false})'));
130128
expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
131129
expect(await getColor(`#hmr-test-1 .label`)).toBe('green');
132130
await (await getEl(`#hmr-test-1 .increment`)).click();

packages/e2e-tests/testUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,10 @@ export async function saveScreenshot(name?: string) {
196196
console.log('failed to take screenshot', e);
197197
}
198198
}
199+
200+
export async function editViteConfig(replacer: (str: string) => string) {
201+
editFile('vite.config.js', replacer);
202+
await sleep(isWin ? 1000 : 500); // editing vite config restarts server, give it some time
203+
await page.goto(viteTestUrl, { waitUntil: 'networkidle' });
204+
await sleep(50);
205+
}

0 commit comments

Comments
 (0)