Skip to content

Commit

Permalink
chore: setup integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Oct 20, 2023
1 parent f04f64d commit 16e06dd
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dist
node_modules
coverage
deno.lock
.DS_Store
.idea

Expand Down
Binary file modified bun.lockb
Binary file not shown.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@
"prepare": "git config --local core.hooksPath .githooks",
"changelog": "gh-changelogen --repo=intlify/utils",
"release": "bumpp --commit \"release: v%s\" --push --tag",
"fix": "run-p lint format",
"lint": "deno lint",
"format": "deno fmt",
"build": "unbuild",
"test": "npm run test:typecheck && npm run test:unit",
"test:unit": "vitest run",
"test:typecheck": "NODE_OPTIONS=--experimental-vm-modules vitest typecheck --run",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules vitest run ./src",
"test:typecheck": "vitest typecheck --config ./vitest.type.config.ts --run",
"test:e2e": "run-s test:e2e:*",
"test:e2e:node": "npm run -w example-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",
Expand All @@ -101,6 +106,7 @@
"h3": "^1.8.1",
"hono": "^3.8.1",
"lint-staged": "^15.0.0",
"npm-run-all": "^4.1.5",
"miniflare": "^3.20231016.0",
"supertest": "^6.3.3",
"typescript": "^5.2.2",
Expand Down
17 changes: 17 additions & 0 deletions playground/bun/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from 'bun:test'

test('bun integration test', async () => {
const process = Bun.spawn(['bun', 'run', './index.ts'], {
stdin: 'inherit',
cwd: import.meta.dir,
})
await Bun.sleep(1000)

const req = new Request('http://localhost:8124')
req.headers.set('accept-language', 'en-US,en;q=0.9,ja;q=0.8')
const res = await fetch(req)
await Bun.sleep(1000)

expect(await res.text()).toBe('detect locale: en-US')
process.kill()
})
1 change: 0 additions & 1 deletion playground/bun/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getHeaderLocale } from '@intlify/utils'

const port = 8124
// @ts-ignore: this is example
Bun.serve({
port,
fetch(req: Request) {
Expand Down
3 changes: 2 additions & 1 deletion playground/bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"module": "index.ts",
"type": "module",
"scripts": {
"dev": "bun run index.ts"
"dev": "bun run index.ts",
"test": "bun test"
},
"devDependencies": {
"bun-types": "latest"
Expand Down
3 changes: 2 additions & 1 deletion playground/deno/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
"dev": "deno run --watch main.ts",
"test": "deno test --allow-read=$(which deno) --allow-run --allow-net ./deno.spec.ts"
}
}
42 changes: 42 additions & 0 deletions playground/deno/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions playground/deno/deno.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { assertEquals } from 'https://deno.land/[email protected]/assert/mod.ts'

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

Deno.test('deno integration test', async () => {
const command = new Deno.Command(Deno.execPath(), {
stdout: 'null',
args: [
'run',
'--allow-net',
'./main.ts',
],
})
const process = command.spawn()
await sleep(1000)

const req = new Request('http://localhost:8125')
req.headers.set('accept-language', 'en-US,en;q=0.9,ja;q=0.8')
const res = await fetch(req)
await sleep(1000)

assertEquals('detect accpect-language: en-US,en,ja', await res.text())

process.kill('SIGINT')
await process.status
})
1 change: 0 additions & 1 deletion playground/deno/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { getHeaderLanguages } from 'https://esm.sh/@intlify/utils'

const port = 8125
// @ts-ignore: this is example
Deno.serve({
port,
}, (req: Request) => {
Expand Down
19 changes: 19 additions & 0 deletions playground/node/node.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import assert from 'node:assert'
import test from 'node:test'
import { spawn } from 'node:child_process'
import { fetch } from 'ofetch'

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

test('node integration test', async () => {
const child = spawn('npx', ['tsx', './index.ts'], { cwd: process.cwd(), stdio: 'inherit' })
await sleep(1000)

const req = new Request('http://localhost:8123')
req.headers.set('accept-language', 'en-US,en;q=0.9,ja;q=0.8')
const res = await fetch(req)
await sleep(1000)

assert.deepEqual('detect accpect-language: en-US,en,ja', await res.text())
child.kill('SIGINT')
})
5 changes: 4 additions & 1 deletion playground/node/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "example-node",
"private": true,
"type": "module",
"scripts": {
"dev": "npx tsx index.ts"
"dev": "npx tsx index.ts",
"test": "node --test"
},
"dependencies": {
"@intlify/utils": "npm:@intlify/utils-edge@latest"
},
"devDependencies": {
"ofetch": "^1.3.3",
"@types/node": "^20.6.0",
"typescript": "^5.2.2"
}
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.vitest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["./tsconfig.json"],
"exclude": ["./playground"]
}
3 changes: 0 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
includeSource: ['src/**/*.{js,ts}'],
// typecheck: {
// ignoreSourceErrors: true,
// },
},
})
12 changes: 12 additions & 0 deletions vitest.type.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vitest/config'
import config from './vitest.config.ts'

export default defineConfig({
...config,
test: {
...config.test,
typecheck: {
tsconfig: './tsconfig.vitest.json',
},
},
})

0 comments on commit 16e06dd

Please sign in to comment.