Skip to content

Commit

Permalink
chore: continue e2e setup
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Oct 20, 2023
1 parent c44e2bb commit c29a151
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 58 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,51 @@ jobs:
- name: Test
run: npm test

e2e:
name: Test
strategy:
matrix:
os: [ubuntu-latest]
node: [18.x]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout codes
uses: actions/checkout@v4

- name: Setup deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Setup bun
uses: oven-sh/setup-bun@v1

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Enable corepack
run: corepack enable

- name: Install dependencies
run: bun install

- name: Build codes
run: npm run build

- name: Run test
run: ./scripts/e2e.sh

edge-release:
name: Edge Release
needs:
- lint
- build
- test
- e2e
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
coverage
.DS_Store
.idea
playground/**/bun.lockb
playground/**/deno.lock

*.log
*.swp
Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage
examples
playground
deno.lock
.*
*.log
Expand Down
Binary file modified bun.lockb
Binary file not shown.
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@
"test": "npm run test:typecheck && npm run test:unit",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules vitest run ./src",
"test:typecheck": "vitest typecheck --config ./vitest.type.config.ts --run",
"test:coverage": "npm test -- --reporter verbose --coverage",
"test:e2e": "run-s test:e2e:*",
"test:e2e:node": "npm run -w example-node test",
"test:e2e:node": "cd playground/node && node --test",
"test:e2e:deno": "cd playground/deno && deno task test",
"test:e2e:bun": "npm run -w example-bun test",
"test:coverage": "npm test -- --reporter verbose --coverage",
"play:browser": "npm run -w example-browser dev",
"play:node": "npm run -w example-node dev",
"test:e2e:bun": "cd playground/bun && npm run test",
"setup": "run-s setup:*",
"setup:browser": "cd playground/browser && bun install",
"setup:node": "cd playground/node && bun install",
"setup:deno": "cd playground/deno && deno cache --reload ./main.ts",
"setup:bun": "cd playground/bun && bun install",
"play:browser": "cd playground/browser && npm run dev",
"play:node": "cd playground/node && npm run dev",
"play:deno": "cd playground/deno && deno run --allow-net main.ts",
"play:bun": "npm run -w example-bun dev"
"play:bun": "cd playground/bun && npm run dev"
},
"lint-staged": {
"*.{js,ts,jsx,tsx,json,jsonc}": [
Expand All @@ -109,12 +114,10 @@
"npm-run-all": "^4.1.5",
"miniflare": "^3.20231016.0",
"supertest": "^6.3.3",
"pkg-types": "^1.0.2",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vitest": "^0.34.6",
"vitest-environment-miniflare": "^2.14.1"
},
"workspaces": [
"playground/*"
]
}
}
39 changes: 0 additions & 39 deletions playground/deno/deno.lock

This file was deleted.

12 changes: 6 additions & 6 deletions playground/deno/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-ignore: this is example
import { getHeaderLanguages } from "@intlify/utils";
import { getHeaderLanguages } from '@intlify/utils'

const port = 8125;
const port = 8125
Deno.serve({
port,
}, (req: Request) => {
const languages = getHeaderLanguages(req);
return new Response(`detect accpect-language: ${languages}`);
});
console.log(`server listening on ${port}`);
const languages = getHeaderLanguages(req)
return new Response(`detect accpect-language: ${languages}`)
})
console.log(`server listening on ${port}`)
7 changes: 5 additions & 2 deletions playground/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
"dependencies": {
"@intlify/utils": "npm:@intlify/utils-edge@latest"
},
"peerDependencies": {
"typescript": "^5.2.2"
},
"devDependencies": {
"ofetch": "^1.3.3",
"@types/node": "^20.6.0",
"typescript": "^5.2.2"
"bun-types": "latest",
"@types/node": "^20.6.0"
}
}
18 changes: 18 additions & 0 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

# Pack packages
npm pack

# Replace deps
bun run ./scripts/replaceDeps.ts

# show the diff of deps
git diff

# setup playground/* for e2e
npm run setup

# just do e2e!
npm run test:e2e
65 changes: 65 additions & 0 deletions scripts/replaceDeps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { constants as FS_CONSTANTS, promises as fs } from 'node:fs'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readPackageJSON, writePackageJSON } from 'pkg-types'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

export async function isExists(path: string) {
try {
await fs.access(path, FS_CONSTANTS.F_OK)
return true
} catch {
return false
}
}

type Platform = 'browser' | 'node' | 'deno' | 'bun'

async function replaceNodePlatform(platform: 'node' | 'bun', playgroundPath: string) {
const utilsPath = resolve(__dirname, '..')
const utilsPkg = await readPackageJSON(resolve(utilsPath, 'package.json'))
const utilsTgzPath = resolve(utilsPath, `intlify-utils-${utilsPkg.version}.tgz`)
if (!await isExists(utilsTgzPath)) {
return false
}
const targetPath = resolve(playgroundPath, platform, 'package.json')
const platformPkg = await readPackageJSON(targetPath)
platformPkg.dependencies![`@intlify/utils`] = `file:${utilsTgzPath}`
await writePackageJSON(targetPath, platformPkg)
return true
}

async function replaceDenoPlatform(playgroundPath: string) {
const denoConfigPath = resolve(playgroundPath, 'deno', 'deno.jsonc')
const denoConfig = JSON.parse(await fs.readFile(denoConfigPath, 'utf-8')) as {
imports: Record<string, unknown>
}
denoConfig['imports']['@intlify/utils'] = '../../src/index.ts'
denoConfig['imports']['cookie-es'] = 'npm:[email protected]'

await fs.writeFile(denoConfigPath, JSON.stringify(denoConfig), 'utf-8')
return true
}

async function main() {
const playgroundPath = resolve(__dirname, '../playground')
for (const platform of (await fs.readdir(playgroundPath)) as Platform[]) {
if (platform === 'node' || platform === 'bun') {
if (!await replaceNodePlatform(platform, playgroundPath)) {
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`)
}
} else if (platform === 'deno') {
if (!await replaceDenoPlatform(playgroundPath)) {
console.error(`cannot replace '@intlify/utils' dependency on ${platform}`)
}
} else { // for browser
// TODO:
}
}
}

main().catch((err) => {
console.error(err)
process.exit(1)
})

0 comments on commit c29a151

Please sign in to comment.