From cfdb38d656fb2238cb6b7de651fcb5b321593cc9 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 11:43:41 +0900 Subject: [PATCH 1/7] fix(vite-node): externalize network imports --- packages/vite-node/src/externalize.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vite-node/src/externalize.ts b/packages/vite-node/src/externalize.ts index 2a579bea6287..e306bbba9a22 100644 --- a/packages/vite-node/src/externalize.ts +++ b/packages/vite-node/src/externalize.ts @@ -95,8 +95,9 @@ async function _shouldExternalize( return id // data: should be processed by native import, - // since it is a feature of ESM - if (id.startsWith('data:')) + // since it is a feature of ESM. + // also externalize network imports since nodejs allows it when --experimental-network-imports + if (id.startsWith('data:') || /^(https?:)?\/\//.test(id)) return id id = patchWindowsImportPath(id) From eb2f72ab6287653db1bb8885b51dae4456e8c8a5 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 12:08:08 +0900 Subject: [PATCH 2/7] ci: tweak playwright --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c72b0bc15e1a..f220ed2bad6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,13 +71,14 @@ jobs: with: node-version: ${{ matrix.node_version }} - - uses: browser-actions/setup-chrome@v1 + # - uses: browser-actions/setup-chrome@v1 - name: Install run: pnpm i - name: Install Playwright Dependencies - run: pnpx playwright install --with-deps + run: pnpx playwright install + # run: pnpx playwright install --with-deps - name: Build run: pnpm run build From aa0d036b3b469219a7413a5e9ad1ccf3d23028bb Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 14 Jan 2024 18:28:50 +0900 Subject: [PATCH 3/7] test: add network-imports test --- pnpm-lock.yaml | 6 ++++++ test/network-imports/package.json | 11 +++++++++++ test/network-imports/test/basic.test.ts | 8 ++++++++ test/network-imports/vitest.config.ts | 11 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 test/network-imports/package.json create mode 100644 test/network-imports/test/basic.test.ts create mode 100644 test/network-imports/vitest.config.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 289d8b66ff2c..ef77ee4326d7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1787,6 +1787,12 @@ importers: specifier: workspace:* version: link:../../packages/vitest + test/network-imports: + devDependencies: + vitest: + specifier: workspace:* + version: link:../../packages/vitest + test/path-resolution: devDependencies: '@edge-runtime/vm': diff --git a/test/network-imports/package.json b/test/network-imports/package.json new file mode 100644 index 000000000000..a8463ad9787e --- /dev/null +++ b/test/network-imports/package.json @@ -0,0 +1,11 @@ +{ + "name": "@vitest/test-network-imports", + "type": "module", + "private": true, + "scripts": { + "test": "vitest" + }, + "devDependencies": { + "vitest": "workspace:*" + } +} diff --git a/test/network-imports/test/basic.test.ts b/test/network-imports/test/basic.test.ts new file mode 100644 index 000000000000..d62af0f152ce --- /dev/null +++ b/test/network-imports/test/basic.test.ts @@ -0,0 +1,8 @@ +import { expect, test } from 'vitest' + +// @ts-expect-error network imports +import slash from 'https://esm.sh/slash@5.1.0' + +test('network imports', async () => { + expect(slash('foo\\bar')).toBe('foo/bar') +}) diff --git a/test/network-imports/vitest.config.ts b/test/network-imports/vitest.config.ts new file mode 100644 index 000000000000..21e92a901577 --- /dev/null +++ b/test/network-imports/vitest.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + poolOptions: { + threads: { + execArgv: ['--experimental-network-imports'], + }, + }, + }, +}) From 3c99b8ae46c1eab35e1c8d6f9721e56c84b2c637 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 12:18:33 +0900 Subject: [PATCH 4/7] Revert "ci: tweak playwright" This reverts commit eb2f72ab6287653db1bb8885b51dae4456e8c8a5. --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f220ed2bad6b..c72b0bc15e1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,14 +71,13 @@ jobs: with: node-version: ${{ matrix.node_version }} - # - uses: browser-actions/setup-chrome@v1 + - uses: browser-actions/setup-chrome@v1 - name: Install run: pnpm i - name: Install Playwright Dependencies - run: pnpx playwright install - # run: pnpx playwright install --with-deps + run: pnpx playwright install --with-deps - name: Build run: pnpm run build From 74cce1f8343372cefb93357633f232b0ce27916c Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 12:22:15 +0900 Subject: [PATCH 5/7] test: tweak --- test/network-imports/test/basic.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/network-imports/test/basic.test.ts b/test/network-imports/test/basic.test.ts index d62af0f152ce..a3bd4661f78d 100644 --- a/test/network-imports/test/basic.test.ts +++ b/test/network-imports/test/basic.test.ts @@ -3,6 +3,6 @@ import { expect, test } from 'vitest' // @ts-expect-error network imports import slash from 'https://esm.sh/slash@5.1.0' -test('network imports', async () => { +test('network imports', () => { expect(slash('foo\\bar')).toBe('foo/bar') }) From ab91ffc4b27b1682c739ac7d613e0fd5f9269588 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 13:05:01 +0900 Subject: [PATCH 6/7] test: use local server instead of esm.sh --- eslint.config.js | 1 + test/network-imports/public/slash@3.0.0.js | 5 +++++ test/network-imports/test/basic.test.ts | 5 ++++- test/network-imports/vitest.config.ts | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/network-imports/public/slash@3.0.0.js diff --git a/eslint.config.js b/eslint.config.js index d3432066a717..624d9673c406 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -13,6 +13,7 @@ export default antfu( 'test/core/src/self', 'test/workspaces/results.json', 'test/reporters/fixtures/with-syntax-error.test.js', + 'test/network-imports/public/slash@3.0.0.js', 'examples/**/mockServiceWorker.js', ], }, diff --git a/test/network-imports/public/slash@3.0.0.js b/test/network-imports/public/slash@3.0.0.js new file mode 100644 index 000000000000..a20adf9eb5bd --- /dev/null +++ b/test/network-imports/public/slash@3.0.0.js @@ -0,0 +1,5 @@ +/* eslint-disable */ +// copied from https://esm.sh/v133/slash@3.0.0/es2022/slash.mjs to reduce network issues in CI + +/* esm.sh - esbuild bundle(slash@3.0.0) es2022 production */ +var a=Object.create;var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),E=(e,t)=>{for(var r in t)d(e,r,{get:t[r],enumerable:!0})},u=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of x(t))!p.call(e,n)&&n!==r&&d(e,n,{get:()=>t[n],enumerable:!(i=m(t,n))||i.enumerable});return e},o=(e,t,r)=>(u(e,t,"default"),r&&u(r,t,"default")),c=(e,t,r)=>(r=e!=null?a(g(e)):{},u(t||!e||!e.__esModule?d(r,"default",{value:e,enumerable:!0}):r,e));var f=A((h,_)=>{"use strict";_.exports=e=>{let t=/^\\\\\?\\/.test(e),r=/[^\u0000-\u0080]+/.test(e);return t||r?e:e.replace(/\\/g,"/")}});var s={};E(s,{default:()=>P});var L=c(f());o(s,c(f()));var{default:l,...N}=L,P=l!==void 0?l:N;export{P as default}; diff --git a/test/network-imports/test/basic.test.ts b/test/network-imports/test/basic.test.ts index a3bd4661f78d..21862089a4c9 100644 --- a/test/network-imports/test/basic.test.ts +++ b/test/network-imports/test/basic.test.ts @@ -1,7 +1,10 @@ import { expect, test } from 'vitest' // @ts-expect-error network imports -import slash from 'https://esm.sh/slash@5.1.0' +import slash from 'http://localhost:9602/slash@3.0.0.js' + +// test without local server +// import slash from 'https://esm.sh/slash@3.0.0' test('network imports', () => { expect(slash('foo\\bar')).toBe('foo/bar') diff --git a/test/network-imports/vitest.config.ts b/test/network-imports/vitest.config.ts index 21e92a901577..f10889788d62 100644 --- a/test/network-imports/vitest.config.ts +++ b/test/network-imports/vitest.config.ts @@ -7,5 +7,7 @@ export default defineConfig({ execArgv: ['--experimental-network-imports'], }, }, + // let vite serve public/slash@3.0.0.js + api: 9602, }, }) From e56382b375749470624eca9717a7a2cd6b3ff4da Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 17 Jan 2024 19:25:58 +0900 Subject: [PATCH 7/7] test: test forks + skip vmThreads --- package.json | 2 +- test/network-imports/vitest.config.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5882e0f1dc24..6d899091f737 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "test:run": "vitest run -r test/core", "test:all": "CI=true pnpm -r --stream run test --allowOnly", "test:ci": "CI=true pnpm -r --stream --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly", - "test:ci:vm-threads": "CI=true pnpm -r --stream --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-browser --filter !example-react-testing-lib-msw run test --allowOnly --pool vmThreads", + "test:ci:vm-threads": "CI=true pnpm -r --stream --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-network-imports --filter !test-browser --filter !example-react-testing-lib-msw run test --allowOnly --pool vmThreads", "test:ci:no-threads": "CI=true pnpm -r --stream --filter !test-vm-threads --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --pool forks", "typecheck": "tsc -p tsconfig.check.json --noEmit", "typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt", diff --git a/test/network-imports/vitest.config.ts b/test/network-imports/vitest.config.ts index f10889788d62..d4fdcc4e457e 100644 --- a/test/network-imports/vitest.config.ts +++ b/test/network-imports/vitest.config.ts @@ -6,6 +6,17 @@ export default defineConfig({ threads: { execArgv: ['--experimental-network-imports'], }, + forks: { + execArgv: ['--experimental-network-imports'], + }, + // not supported? + // FAIL test/basic.test.ts [ test/basic.test.ts ] + // Error: ENOENT: no such file or directory, open 'http://localhost:9602/slash@3.0.0.js' + // ❯ Object.openSync node:fs:596:3 + // ❯ readFileSync node:fs:464:35 + vmThreads: { + execArgv: ['--experimental-network-imports'], + }, }, // let vite serve public/slash@3.0.0.js api: 9602,