Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Menci committed Dec 19, 2024
1 parent 740c00f commit 4120a3d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
38 changes: 24 additions & 14 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/// <reference types="jest-extended" />
/* istanbul ignore file */

import path from "path";
import url from "url";
import fs from "fs";
import type { AddressInfo } from "net";

import { jest } from "@jest/globals";
import { firefox } from "playwright";

Expand All @@ -10,9 +15,7 @@ import vitePluginWasm from "../src/index.js";
import express from "express";
import waitPort from "wait-port";
import mime from "mime";
import path from "path";
import url from "url";
import type { AddressInfo } from "net";
import { temporaryDirectory } from "tempy";

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

Expand Down Expand Up @@ -44,7 +47,7 @@ type VitePackages =
};

async function buildAndStartProdServer(
viteVersion: number,
tempDir: string,
vitePackages: VitePackages,
transformTopLevelAwait: boolean,
modernOnly: boolean
Expand All @@ -54,9 +57,10 @@ async function buildAndStartProdServer(
const result = await vite.build({
root: __dirname,
build: {
target: "esnext"
target: "esnext",
outDir: path.resolve(tempDir, "dist")
},
cacheDir: path.resolve(__dirname, "node_modules", `.vite${viteVersion}`),
cacheDir: path.resolve(tempDir, ".vite"),
plugins: [
...(modernOnly ? [] : [vitePluginLegacy()]),
vitePluginWasm(),
Expand Down Expand Up @@ -105,13 +109,13 @@ async function buildAndStartProdServer(
return `http://127.0.0.1:${port}/`;
}

async function startDevServer(viteVersion: number, vitePackages: VitePackages): Promise<string> {
async function startDevServer(tempDir: string, vitePackages: VitePackages): Promise<string> {
const { vite } = vitePackages;

const devServer = await vite.createServer({
root: __dirname,
plugins: [vitePluginWasm()],
cacheDir: path.resolve(__dirname, "node_modules", `.vite${viteVersion}`),
cacheDir: path.resolve(tempDir, ".vite"),
logLevel: "error"
});

Expand All @@ -134,14 +138,20 @@ async function createBrowser(modernBrowser: boolean) {
}

async function runTest(
viteVersion: number,
vitePackages: VitePackages,
devServer: boolean,
transformTopLevelAwait: boolean,
modernBrowser: boolean
) {
const tempDir = temporaryDirectory();
process.on("exit", () => {
try {
fs.rmdirSync(tempDir, { recursive: true });
} catch {}
});

const server = await (devServer ? startDevServer : buildAndStartProdServer)(
viteVersion,
tempDir,
vitePackages,
transformTopLevelAwait,
modernBrowser
Expand Down Expand Up @@ -208,19 +218,19 @@ export function runTests(viteVersion: number, importVitePackages: () => Promise<
}

it(`vite ${viteVersion}: should work on modern browser in Vite dev server`, async () => {
await runTestWithRetry(viteVersion, await importVitePackages(), true, false, true);
await runTestWithRetry(await importVitePackages(), true, false, true);
});

it(`vite ${viteVersion}: should work on modern browser without top-level await transform`, async () => {
await runTestWithRetry(viteVersion, await importVitePackages(), false, false, true);
await runTestWithRetry(await importVitePackages(), false, false, true);
});

it(`vite ${viteVersion}: should work on modern browser with top-level await transform`, async () => {
await runTestWithRetry(viteVersion, await importVitePackages(), false, true, true);
await runTestWithRetry(await importVitePackages(), false, true, true);
});

it(`vite ${viteVersion}: should work on legacy browser`, async () => {
await runTestWithRetry(viteVersion, await importVitePackages(), false, true, false);
await runTestWithRetry(await importVitePackages(), false, true, false);
});
});
}
3 changes: 3 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"private": true,
"scripts": {
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5 && yarn --cwd vite6"
},
"dependencies": {
"tempy": "^3.1.0"
}
}
43 changes: 43 additions & 0 deletions e2e/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,46 @@
# yarn lockfile v1


crypto-random-string@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-4.0.0.tgz#5a3cc53d7dd86183df5da0312816ceeeb5bb1fc2"
integrity sha512-x8dy3RnvYdlUcPOjkEHqozhiwzKNSq7GcPuXFbnyMOCHxX8V3OgIg/pYuabl2sbUPfIJaeAQB7PMOK8DFIdoRA==
dependencies:
type-fest "^1.0.1"

is-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac"
integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==

temp-dir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-3.0.0.tgz#7f147b42ee41234cc6ba3138cd8e8aa2302acffa"
integrity sha512-nHc6S/bwIilKHNRgK/3jlhDoIHcp45YgyiwcAk46Tr0LfEqGBVpmiAyuiuxeVE44m3mXnEeVhaipLOEWmH+Njw==

tempy@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/tempy/-/tempy-3.1.0.tgz#00958b6df85db8589cb595465e691852aac038e9"
integrity sha512-7jDLIdD2Zp0bDe5r3D2qtkd1QOCacylBuL7oa4udvN6v2pqr4+LcCr67C8DR1zkpaZ8XosF5m1yQSabKAW6f2g==
dependencies:
is-stream "^3.0.0"
temp-dir "^3.0.0"
type-fest "^2.12.2"
unique-string "^3.0.0"

type-fest@^1.0.1:
version "1.4.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"
integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==

type-fest@^2.12.2:
version "2.19.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==

unique-string@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-3.0.0.tgz#84a1c377aff5fd7a8bc6b55d8244b2bd90d75b9a"
integrity sha512-VGXBUVwxKMBUznyffQweQABPRRW1vHZAbadFZud4pLFAqRGvv/96vafgjWFqzourzr8YonlQiPgH0YCJfawoGQ==
dependencies:
crypto-random-string "^4.0.0"

0 comments on commit 4120a3d

Please sign in to comment.