Skip to content

Commit

Permalink
feat: support Vite 5 (#45)
Browse files Browse the repository at this point in the history
* Attempt at updating to vite 5

* Fix test

* Skip test on unsupported Node/Vite version combinations

* Lock playwright version

* Upgrade dependencies

* FORCE Upgrade dependencies

* Move dependencies to devDependencies

* Set yarn to ignore engines version check in CI

* yarn format

* Fix skipped tests on Node.js 14

---------

Co-authored-by: Menci <[email protected]>
  • Loading branch information
wyatt-herkamp and Menci authored Dec 11, 2023
1 parent dbe2779 commit 9d500ce
Show file tree
Hide file tree
Showing 13 changed files with 3,977 additions and 2,644 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Set yarn to ignore engines version check
run: yarn config set ignore-engines true
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Build
Expand Down
23 changes: 17 additions & 6 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type VitePackages =
vite: typeof import("./vite4/node_modules/vite");
vitePluginLegacy: (typeof import("./vite4/node_modules/@vitejs/plugin-legacy"))["default"];
vitePluginTopLevelAwait: (typeof import("./vite4/node_modules/vite-plugin-top-level-await"))["default"];
}
| {
vite: typeof import("./vite5/node_modules/vite");
vitePluginLegacy: (typeof import("./vite5/node_modules/@vitejs/plugin-legacy"))["default"];
vitePluginTopLevelAwait: (typeof import("./vite5/node_modules/vite-plugin-top-level-await"))["default"];
};

async function buildAndStartProdServer(
Expand Down Expand Up @@ -75,7 +80,7 @@ async function buildAndStartProdServer(
if (filePath in bundle) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
const contentType = mime.lookup(filePath);
const contentType = mime.getType(filePath);
const contentTypeWithEncoding = contentType + (contentType.includes("text/") ? "; charset=utf-8" : "");
res.contentType(contentTypeWithEncoding);
res.send(bundle[filePath]);
Expand Down Expand Up @@ -183,24 +188,30 @@ const runTestWithRetry = async (...args: Parameters<typeof runTest>) => {
}
};

export function runTests(viteVersion: number, vitePackages: VitePackages) {
export function runTests(viteVersion: number, importVitePackages: () => Promise<VitePackages>) {
jest.setTimeout(60000);

describe(`E2E test for Vite ${viteVersion}`, () => {
const nodeVersion = Number(process.versions.node.split(".")[0]);
if (viteVersion >= 5 && nodeVersion < 18) {
it(`vite ${viteVersion}: skipped on Node.js ${nodeVersion}`, async () => {});
return;
}

it(`vite ${viteVersion}: should work on modern browser in Vite dev server`, async () => {
await runTestWithRetry(vitePackages, 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(vitePackages, 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(vitePackages, false, true, true);
await runTestWithRetry(await importVitePackages(), false, true, true);
});

it(`vite ${viteVersion}: should work on legacy browser`, async () => {
await runTestWithRetry(vitePackages, false, true, false);
await runTestWithRetry(await importVitePackages(), false, true, false);
});
});
}
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"license": "MIT",
"private": true,
"scripts": {
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4"
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5"
}
}
}
14 changes: 5 additions & 9 deletions e2e/vite2/e2e-vite2.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as vite from "vite";
import { default as vitePluginLegacy } from "@vitejs/plugin-legacy";
import { default as vitePluginTopLevelAwait } from "vite-plugin-top-level-await";

import { runTests } from "../e2e";

runTests(2, {
vite,
vitePluginLegacy,
vitePluginTopLevelAwait
});
runTests(2, async () => ({
vite: await import("vite"),
vitePluginLegacy: (await import("@vitejs/plugin-legacy")).default,
vitePluginTopLevelAwait: (await import("vite-plugin-top-level-await")).default
}));
14 changes: 5 additions & 9 deletions e2e/vite3/e2e-vite3.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as vite from "vite";
import { default as vitePluginLegacy } from "@vitejs/plugin-legacy";
import { default as vitePluginTopLevelAwait } from "vite-plugin-top-level-await";

import { runTests } from "../e2e";

runTests(3, {
vite,
vitePluginLegacy,
vitePluginTopLevelAwait
});
runTests(3, async () => ({
vite: await import("vite"),
vitePluginLegacy: (await import("@vitejs/plugin-legacy")).default,
vitePluginTopLevelAwait: (await import("vite-plugin-top-level-await")).default
}));
14 changes: 5 additions & 9 deletions e2e/vite4/e2e-vite4.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as vite from "vite";
import { default as vitePluginLegacy } from "@vitejs/plugin-legacy";
import { default as vitePluginTopLevelAwait } from "vite-plugin-top-level-await";

import { runTests } from "../e2e";

runTests(4, {
vite,
vitePluginLegacy,
vitePluginTopLevelAwait
});
runTests(4, async () => ({
vite: await import("vite"),
vitePluginLegacy: (await import("@vitejs/plugin-legacy")).default,
vitePluginTopLevelAwait: (await import("vite-plugin-top-level-await")).default
}));
7 changes: 7 additions & 0 deletions e2e/vite5/e2e-vite5.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { runTests } from "../e2e";

runTests(5, async () => ({
vite: await import("vite"),
vitePluginLegacy: (await import("@vitejs/plugin-legacy")).default,
vitePluginTopLevelAwait: (await import("vite-plugin-top-level-await")).default
}));
12 changes: 12 additions & 0 deletions e2e/vite5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "dependencies-vite5",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"devDependencies": {
"@vitejs/plugin-legacy": "^5",
"vite": "5",
"vite-plugin-top-level-await": "^1.1.1"
}
}
Loading

0 comments on commit 9d500ce

Please sign in to comment.