Skip to content

Commit

Permalink
Run time zone tests with Bun (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jan 22, 2024
1 parent f578327 commit 6f44a16
Show file tree
Hide file tree
Showing 256 changed files with 857 additions and 349 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/timezone_step_1.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/timezone_step_2.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/timezone_step_3.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/timezone_step_4.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/timezone_step_5.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/tz_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Time zone tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun ./scripts/test/tzOffset.ts
- run: bun ./scripts/test/tzIANA.ts
136 changes: 136 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6025,6 +6025,7 @@
"@octokit/core": "^3.2.5",
"@size-limit/esbuild": "^11.0.1",
"@size-limit/file": "^11.0.1",
"@types/bun": "^1.0.3",
"@types/lodash": "^4.14.202",
"@types/node": "^20.10.2",
"@types/sinon": "^9.0.6",
Expand All @@ -6033,6 +6034,7 @@
"@vitest/browser": "^0.34.6",
"@vitest/coverage-v8": "^0.34.6",
"babel-plugin-add-import-extension": "^1.6.0",
"bun": "^1.0.25",
"cloc": "^2.2.0",
"coveralls": "^3.1.1",
"eslint": "^8.55.0",
Expand Down
32 changes: 32 additions & 0 deletions scripts/test/_lib/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export function promiseQueue<Type>(
promises: Array<() => Promise<Type>>,
max: number,
): Promise<Type[]> {
const queue: Array<() => void> = [];

const all = Promise.all<Type>(
new Array(promises.length).fill(null).map((_, index) => {
const promise = new Promise<void>((resolve) => {
queue[index] = () => {
// Trigger the queue promise
resolve();
// Return it, so the worker function can wait for
return promise;
};
}).then(() => promises[index]());
return promise;
}),
);

async function next() {
const promise = queue.shift();
if (!promise) return;
await promise();
return next();
}

// Create the worker functions
Promise.all(new Array(max).fill(null).map(() => next()));

return all;
}
23 changes: 23 additions & 0 deletions scripts/test/_lib/tz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { $ } from "bun";
import { availableParallelism } from "node:os";
import { promiseQueue } from "./queue";

export async function testTimeZone(timeZone: string) {
const { stderr, exitCode } =
await $`TZ=${timeZone} bun test ./src/**/test.ts`.quiet();

if (exitCode) {
console.log(stderr.toString());
console.log(`⛔ Tests for the time zone ${timeZone}`);
process.exit(exitCode);
}

console.log(`✅ Tests for the time zone ${timeZone}`);
}

export function testTimeZones(timeZones: string[]) {
return promiseQueue(
timeZones.map((timeZone) => () => testTimeZone(timeZone)),
availableParallelism(),
);
}

0 comments on commit 6f44a16

Please sign in to comment.