Skip to content

Commit c29a151

Browse files
committed
chore: continue e2e setup
1 parent c44e2bb commit c29a151

File tree

10 files changed

+149
-58
lines changed

10 files changed

+149
-58
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,51 @@ jobs:
106106
- name: Test
107107
run: npm test
108108

109+
e2e:
110+
name: Test
111+
strategy:
112+
matrix:
113+
os: [ubuntu-latest]
114+
node: [18.x]
115+
116+
runs-on: ${{ matrix.os }}
117+
118+
steps:
119+
- name: Checkout codes
120+
uses: actions/checkout@v4
121+
122+
- name: Setup deno
123+
uses: denoland/setup-deno@v1
124+
with:
125+
deno-version: v1.x
126+
127+
- name: Setup bun
128+
uses: oven-sh/setup-bun@v1
129+
130+
- name: Setup node
131+
uses: actions/setup-node@v3
132+
with:
133+
node-version: ${{ matrix.node }}
134+
135+
- name: Enable corepack
136+
run: corepack enable
137+
138+
- name: Install dependencies
139+
run: bun install
140+
141+
- name: Build codes
142+
run: npm run build
143+
144+
- name: Run test
145+
run: ./scripts/e2e.sh
146+
109147
edge-release:
110148
name: Edge Release
111149
needs:
112150
- lint
113151
- build
114152
- test
153+
- e2e
115154
runs-on: ${{ matrix.os }}
116155
strategy:
117156
matrix:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ node_modules
33
coverage
44
.DS_Store
55
.idea
6+
playground/**/bun.lockb
7+
playground/**/deno.lock
68

79
*.log
810
*.swp

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage
2-
examples
2+
playground
33
deno.lock
44
.*
55
*.log

bun.lockb

-693 Bytes
Binary file not shown.

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@
7676
"test": "npm run test:typecheck && npm run test:unit",
7777
"test:unit": "NODE_OPTIONS=--experimental-vm-modules vitest run ./src",
7878
"test:typecheck": "vitest typecheck --config ./vitest.type.config.ts --run",
79+
"test:coverage": "npm test -- --reporter verbose --coverage",
7980
"test:e2e": "run-s test:e2e:*",
80-
"test:e2e:node": "npm run -w example-node test",
81+
"test:e2e:node": "cd playground/node && node --test",
8182
"test:e2e:deno": "cd playground/deno && deno task test",
82-
"test:e2e:bun": "npm run -w example-bun test",
83-
"test:coverage": "npm test -- --reporter verbose --coverage",
84-
"play:browser": "npm run -w example-browser dev",
85-
"play:node": "npm run -w example-node dev",
83+
"test:e2e:bun": "cd playground/bun && npm run test",
84+
"setup": "run-s setup:*",
85+
"setup:browser": "cd playground/browser && bun install",
86+
"setup:node": "cd playground/node && bun install",
87+
"setup:deno": "cd playground/deno && deno cache --reload ./main.ts",
88+
"setup:bun": "cd playground/bun && bun install",
89+
"play:browser": "cd playground/browser && npm run dev",
90+
"play:node": "cd playground/node && npm run dev",
8691
"play:deno": "cd playground/deno && deno run --allow-net main.ts",
87-
"play:bun": "npm run -w example-bun dev"
92+
"play:bun": "cd playground/bun && npm run dev"
8893
},
8994
"lint-staged": {
9095
"*.{js,ts,jsx,tsx,json,jsonc}": [
@@ -109,12 +114,10 @@
109114
"npm-run-all": "^4.1.5",
110115
"miniflare": "^3.20231016.0",
111116
"supertest": "^6.3.3",
117+
"pkg-types": "^1.0.2",
112118
"typescript": "^5.2.2",
113119
"unbuild": "^2.0.0",
114120
"vitest": "^0.34.6",
115121
"vitest-environment-miniflare": "^2.14.1"
116-
},
117-
"workspaces": [
118-
"playground/*"
119-
]
122+
}
120123
}

playground/deno/deno.lock

Lines changed: 0 additions & 39 deletions
This file was deleted.

playground/deno/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// @ts-ignore: this is example
2-
import { getHeaderLanguages } from "@intlify/utils";
2+
import { getHeaderLanguages } from '@intlify/utils'
33

4-
const port = 8125;
4+
const port = 8125
55
Deno.serve({
66
port,
77
}, (req: Request) => {
8-
const languages = getHeaderLanguages(req);
9-
return new Response(`detect accpect-language: ${languages}`);
10-
});
11-
console.log(`server listening on ${port}`);
8+
const languages = getHeaderLanguages(req)
9+
return new Response(`detect accpect-language: ${languages}`)
10+
})
11+
console.log(`server listening on ${port}`)

playground/node/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
"dependencies": {
1010
"@intlify/utils": "npm:@intlify/utils-edge@latest"
1111
},
12+
"peerDependencies": {
13+
"typescript": "^5.2.2"
14+
},
1215
"devDependencies": {
1316
"ofetch": "^1.3.3",
14-
"@types/node": "^20.6.0",
15-
"typescript": "^5.2.2"
17+
"bun-types": "latest",
18+
"@types/node": "^20.6.0"
1619
}
1720
}

scripts/e2e.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Pack packages
6+
npm pack
7+
8+
# Replace deps
9+
bun run ./scripts/replaceDeps.ts
10+
11+
# show the diff of deps
12+
git diff
13+
14+
# setup playground/* for e2e
15+
npm run setup
16+
17+
# just do e2e!
18+
npm run test:e2e

scripts/replaceDeps.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { constants as FS_CONSTANTS, promises as fs } from 'node:fs'
2+
import { resolve } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { readPackageJSON, writePackageJSON } from 'pkg-types'
5+
6+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
7+
8+
export async function isExists(path: string) {
9+
try {
10+
await fs.access(path, FS_CONSTANTS.F_OK)
11+
return true
12+
} catch {
13+
return false
14+
}
15+
}
16+
17+
type Platform = 'browser' | 'node' | 'deno' | 'bun'
18+
19+
async function replaceNodePlatform(platform: 'node' | 'bun', playgroundPath: string) {
20+
const utilsPath = resolve(__dirname, '..')
21+
const utilsPkg = await readPackageJSON(resolve(utilsPath, 'package.json'))
22+
const utilsTgzPath = resolve(utilsPath, `intlify-utils-${utilsPkg.version}.tgz`)
23+
if (!await isExists(utilsTgzPath)) {
24+
return false
25+
}
26+
const targetPath = resolve(playgroundPath, platform, 'package.json')
27+
const platformPkg = await readPackageJSON(targetPath)
28+
platformPkg.dependencies![`@intlify/utils`] = `file:${utilsTgzPath}`
29+
await writePackageJSON(targetPath, platformPkg)
30+
return true
31+
}
32+
33+
async function replaceDenoPlatform(playgroundPath: string) {
34+
const denoConfigPath = resolve(playgroundPath, 'deno', 'deno.jsonc')
35+
const denoConfig = JSON.parse(await fs.readFile(denoConfigPath, 'utf-8')) as {
36+
imports: Record<string, unknown>
37+
}
38+
denoConfig['imports']['@intlify/utils'] = '../../src/index.ts'
39+
denoConfig['imports']['cookie-es'] = 'npm:[email protected]'
40+
41+
await fs.writeFile(denoConfigPath, JSON.stringify(denoConfig), 'utf-8')
42+
return true
43+
}
44+
45+
async function main() {
46+
const playgroundPath = resolve(__dirname, '../playground')
47+
for (const platform of (await fs.readdir(playgroundPath)) as Platform[]) {
48+
if (platform === 'node' || platform === 'bun') {
49+
if (!await replaceNodePlatform(platform, playgroundPath)) {
50+
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`)
51+
}
52+
} else if (platform === 'deno') {
53+
if (!await replaceDenoPlatform(playgroundPath)) {
54+
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`)
55+
}
56+
} else { // for browser
57+
// TODO:
58+
}
59+
}
60+
}
61+
62+
main().catch((err) => {
63+
console.error(err)
64+
process.exit(1)
65+
})

0 commit comments

Comments
 (0)