From 4d8f3978f6b87f9908a1340673af73a3fd9f880c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 13 Jun 2021 22:16:38 +0800 Subject: [PATCH] chore: fix test --- packages/playground/fs-serve/__tests__/fs-serve.spec.ts | 4 ++-- packages/playground/fs-serve/{ => root}/vite.config.ts | 9 +++------ scripts/jestPerTestSetup.ts | 6 +++++- 3 files changed, 10 insertions(+), 9 deletions(-) rename packages/playground/fs-serve/{ => root}/vite.config.ts (55%) diff --git a/packages/playground/fs-serve/__tests__/fs-serve.spec.ts b/packages/playground/fs-serve/__tests__/fs-serve.spec.ts index dc2f3d80aa1227..8eb4babc72826c 100644 --- a/packages/playground/fs-serve/__tests__/fs-serve.spec.ts +++ b/packages/playground/fs-serve/__tests__/fs-serve.spec.ts @@ -1,6 +1,6 @@ import { isBuild } from '../../testUtils' -const json = require('../../json/test.json') +const json = require('../safe.json') const stringified = JSON.stringify(json) if (!isBuild) { @@ -9,7 +9,7 @@ if (!isBuild) { }) test('named import', async () => { - expect(await page.textContent('.named')).toBe(json.hello) + expect(await page.textContent('.named')).toBe(json.msg) }) test('safe fetch', async () => { diff --git a/packages/playground/fs-serve/vite.config.ts b/packages/playground/fs-serve/root/vite.config.ts similarity index 55% rename from packages/playground/fs-serve/vite.config.ts rename to packages/playground/fs-serve/root/vite.config.ts index 4902654187e0d3..b61810167156dd 100644 --- a/packages/playground/fs-serve/vite.config.ts +++ b/packages/playground/fs-serve/root/vite.config.ts @@ -1,13 +1,10 @@ -import { resolve } from 'path' +import { dirname } from 'path' import { defineConfig } from 'vite' -const root = resolve(__dirname, 'root') - export default defineConfig({ - root, server: { fsServe: { - root, + root: __dirname, strict: true }, hmr: { @@ -15,6 +12,6 @@ export default defineConfig({ } }, define: { - ROOT: JSON.stringify(__dirname.replace(/\\/g, '/')) + ROOT: JSON.stringify(dirname(__dirname).replace(/\\/g, '/')) } }) diff --git a/scripts/jestPerTestSetup.ts b/scripts/jestPerTestSetup.ts index f240ac430e056d..20afe4b2473359 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/jestPerTestSetup.ts @@ -68,8 +68,12 @@ beforeAll(async () => { return } + // when `root` dir is present, use it as vite's root + let testCustomRoot = resolve(tempDir, 'root') + if (!fs.existsSync(testCustomRoot)) testCustomRoot = tempDir + const options: UserConfig = { - root: tempDir, + root: testCustomRoot, logLevel: 'silent', server: { watch: {