Skip to content

Commit

Permalink
refactor: ensure all tests with Bun and Deno (#680)
Browse files Browse the repository at this point in the history
* refactor: better organize tests

* debug: fix ci

* debug: use stable Bun version

* debug: fix legacy compatibility

* docs: adjust docs

* docs: improve Deno description

* debug: fix Windows ci

* debug: fix import order

* ci: restaure background services tests

* debug: fix Windows ci
  • Loading branch information
wellwelwel authored Aug 14, 2024
1 parent 7b36071 commit c7020ae
Show file tree
Hide file tree
Showing 179 changed files with 764 additions and 924 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
website/** linguist-documentation
test/docker/** linguist-vendored
fixtures/** linguist-vendored
test/__docker__/** linguist-vendored
test/__fixtures__/** linguist-vendored
benchmark/** linguist-vendored
src/bin/** linguist-language=TypeScript
10 changes: 7 additions & 3 deletions .github/workflows/ci_compatibility-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
bun-version: ['latest', 'canary']
bun-version: ['1.1.22']
name: Bun ${{ matrix.bun-version }}
steps:
- name: ➕ Actions - Checkout
Expand All @@ -22,6 +22,11 @@ jobs:
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun-version }}

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand All @@ -35,6 +40,5 @@ jobs:
- name: 🤹🏻‍♀️ Building the Project
run: npm run build

# Testing via Docker Official Images
- name: 🔬 Bun ${{ matrix.bun-version }}
run: FILTER=bun-${{ matrix.bun-version }} npm run test:ci
run: npm run test:bun:parallel
10 changes: 7 additions & 3 deletions .github/workflows/ci_compatibility-deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
deno-version: ['latest']
deno-version: ['v1.x', 'canary']
name: Deno ${{ matrix.deno-version }}
steps:
- name: ➕ Actions - Checkout
Expand All @@ -22,6 +22,11 @@ jobs:
with:
node-version: '22.x'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand All @@ -35,6 +40,5 @@ jobs:
- name: 🤹🏻‍♀️ Building the Project
run: npm run build

# Testing via Docker Official Images
- name: 🔬 Deno ${{ matrix.deno-version }}
run: FILTER=deno-${{ matrix.deno-version }} npm run test:ci
run: npm run test:deno:parallel
12 changes: 9 additions & 3 deletions .github/workflows/ci_compatibility-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: ['08', '10', '12', '14', '16', '18', '20', 'latest']
node-version: ['08', '10', '12', '14', '16', '18', '20', '22']
name: Node.js ${{ matrix.node-version }}
steps:
- name: ➕ Actions - Checkout
Expand All @@ -22,6 +22,11 @@ jobs:
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.1.22'

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand All @@ -35,6 +40,7 @@ jobs:
- name: 🤹🏻‍♀️ Building the Project
run: npm run build

# Testing via Docker Official Images
- name: 🔬 Node ${{ matrix.node-version }}
run: FILTER=node-${{ matrix.node-version }} npm run test:ci
run: npm run test:docker:node
env:
FILTER: node-${{ matrix.node-version }}
4 changes: 2 additions & 2 deletions .github/workflows/ci_coverage-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2
with:
bun-version: 'latest'
bun-version: '1.1.22'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
Expand Down
21 changes: 10 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
node_modules
.DS_Store
/lib
/ci
/playground
/coverage
.env
.nyc_output
/.temp
/.temp2
/test-src
/test-tests
/test-before-and-after-each.json
.nycrc.json

/lib/
/ci/
/playground/
/coverage/
/test/__fixtures__/.temp/

node_modules/

!/test/__fixtures__/e2e/env/.env
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/ci
/CHANGELOG.md
/website
/fixtures/sintax
/test/__fixtures__/e2e/sintax
/.nycrc.json
36 changes: 3 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ It's better to discuss an **API** before actually start implementing it. You can

Check if there is an existing section or feel free to create a new one. You can find the wesite source code at [./website](https://github.com/wellwelwel/poku/tree/main/website).

- Feel free to open PRs fixing typos or adding support for other languages 🤝
- Feel free to open _PRs_ fixing typos or adding support for more languages 🤝

<blockquote>

Expand Down Expand Up @@ -126,38 +126,8 @@ npm run test:c8:sequential
> [!tip]
>
> Don't be intimidated by high coverage, methods that vary according to platform, platform versions, _OS_ and processes _(`process.exit`, `process.once`, etc.)_ aren't tested against the coverage rate 🙋🏻‍♂️
### 🐳 Compatibility Per Platform (Docker)

> ⚠️ Testing using **Docker** can require a considerable local storage.
```sh
npm run build # Build the Project
```

```sh
npm run test:ci:node # All Node.js versions from 6+
npm run test:ci:bun # All Bun versions from 1+
npm run test:ci:deno # All Deno versions from 1+
```

- You may prefer to use **GitHub Actions** for compatibility testing.
- For **Windows** users, it's recommended to use [**wsl**](https://learn.microsoft.com/en-us/windows/wsl/install).

### 🐋 Compatibility (All Platforms — Docker)

> ⚠️ Slow and heavy
```sh
npm run build # Build the Project
```

```sh
npm run test:ci
```

- You may prefer to use **GitHub Actions** for compatibility testing.
- For **Windows** users, it's recommended to use [**wsl**](https://learn.microsoft.com/en-us/windows/wsl/install).
>
> See more details in [**./.nycrc**](https://github.com/wellwelwel/poku/tree/main/.nycrc).
---

Expand Down
11 changes: 5 additions & 6 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"files": {
"include": ["**/**"],
"ignore": [
"node_modules",
"lib",
"benchmark",
"ci",
"coverage",
"website",
"fixtures",
"benchmark",
"fixtures/sintax"
"lib",
"node_modules",
"test/__fixtures__",
"website"
]
},
"organizeImports": {
Expand Down
3 changes: 3 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"unstable": ["sloppy-imports"]
}
3 changes: 0 additions & 3 deletions fixtures/fail/assert-fail-message.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/fail/assert-fail.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/fail/assert-if-error.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/fail/assert.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/skip-and-todo/skip.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/skip-and-todo/todo.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/skip-todo-and-failure/skip.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/skip-todo-and-failure/todo.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/skip/skip.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/final-results/todo/todo.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/watch/test/a.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/watch/test/b.test.ts

This file was deleted.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,16 @@
"test:parallel": "tsx src/bin/index.ts -p test/unit test/integration test/e2e",
"test:bun:sequential": "bun src/bin/index.ts --bun test/unit test/integration test/e2e",
"test:bun:parallel": "bun src/bin/index.ts --bun -p test/unit test/integration test/e2e",
"test:deno:sequential": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs ci/test/unit ci/test/integration ci/test/e2e",
"test:deno:parallel": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs -p ci/test/unit ci/test/integration ci/test/e2e",
"test:deno:sequential": "tsx src/bin/index.ts --deno --deno-allow=all test/unit test/integration test/e2e",
"test:deno:parallel": "tsx src/bin/index.ts --deno --deno-allow=all -p test/unit test/integration test/e2e",
"pretest:c8": "tsx tools/build/c8-file.ts",
"test:c8": "c8 --experimental-monocart tsx test/c8.test.ts",
"posttest:c8": "rm -rf ./.nycrc.json",
"test:ci": "tsx test/ci.test.ts",
"test:ci:node": "FILTER='node-' npm run test:ci",
"test:ci:bun": "FILTER='bun-' npm run test:ci",
"test:ci:deno": "FILTER='deno-' npm run test:ci",
"predocker:deno": "docker compose -f test/docker/playground/deno/docker-compose.yml down",
"docker:deno": "docker compose -f test/docker/playground/deno/docker-compose.yml up --build",
"test:docker:node": "tsx test/ci.test.ts",
"clear": "rm -rf lib ci coverage .temp test-src test-tests",
"prebuild": "npm run clear",
"build": "tsc && tsc -p tsconfig.test.json",
"postbuild": "tsx tools/compatibility/node.ts && tsx tools/compatibility/comments.ts && tsx tools/build/version.ts && cp fixtures/server/package.json ci/fixtures/server/package.json && rm -f ./lib/@types/*.js ./lib/bin/*.ts && npm run build:deno && chmod +x lib/bin/index.js",
"build": "tsc && cd test && tsc",
"postbuild": "tsx tools/compatibility/node.ts && tsx tools/compatibility/comments.ts && tsx tools/build/version.ts && cp test/__fixtures__/e2e/server/package.json ci/test/__fixtures__/e2e/server/package.json && rm -f ./lib/@types/*.js ./lib/bin/*.ts && npm run build:deno && chmod +x lib/bin/index.js",
"build:deno": "tsc -p tsconfig.mjs.json",
"postbuild:deno": "tsx tools/build/check-deno-polyfill.ts",
"lint": "npx @biomejs/biome lint && prettier --check .",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ export const startWatch = async (dirs: string[], options: Configs) => {
`${format('Watching:').bold()} ${format(dirs.join(', ')).underline()}`
);

process.stdin.setEncoding('utf-8');
process.stdin.setEncoding('utf8');
process.stdin.on('data', listenStdin);
};
3 changes: 3 additions & 0 deletions src/modules/helpers/create-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const backgroundProcess = (

const PID = service.pid!;

service.stdout.setEncoding('utf8');
service.stderr.setEncoding('utf8');

let portBackup: number | undefined;

const end: End = (port) =>
Expand Down
5 changes: 3 additions & 2 deletions src/modules/helpers/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { env as processEnv } from 'node:process';
import { readFile } from '../../polyfills/fs.js';
import { sanitizePath } from './list-files.js';
import {
Expand Down Expand Up @@ -25,11 +26,11 @@ export const envFile = async (filePath = '.env') => {
if (parsedLine) {
const { arg, value } = parsedLine;

mapEnv.set(arg, value ? resolveEnvVariables(value, process.env) : value);
mapEnv.set(arg, value ? resolveEnvVariables(value, processEnv) : value);
}
}

for (const [arg, value] of mapEnv) {
process.env[arg] = value;
processEnv[arg] = value;
}
};
2 changes: 1 addition & 1 deletion src/parsers/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getConfigs = async (
return require(`file://${normalize(filePath)}`);
}

const configsFile = await readFile(filePath, 'utf-8');
const configsFile = await readFile(filePath, 'utf8');
return JSONC.parse<ConfigJSONFile>(configsFile);
} catch {}
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const runDockerCommand = (
});

if (verbose) {
dockerProcess.stdout.setEncoding('utf8');
dockerProcess.stderr.setEncoding('utf8');
dockerProcess.stdout.on('data', Write.log);
dockerProcess.stderr.on('data', Write.log);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/map-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const processDeepImports = async (
}
processedFiles.add(srcFile);

const srcContent = await readFile(srcFile, 'utf-8');
const srcContent = await readFile(srcFile, 'utf8');
const deepImports = getDeepImports(srcContent);
const matchingFiles = findMatchingFiles(deepImports, intersectedSrcFiles);

Expand All @@ -126,7 +126,7 @@ export const createImportMap = async (

await Promise.all(
Array.from(allTestFiles).map(async (testFile) => {
const content = await readFile(testFile, 'utf-8');
const content = await readFile(testFile, 'utf8');

for (const srcFile of intersectedSrcFiles) {
const relativePath = normalizePath(
Expand Down
2 changes: 2 additions & 0 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const runTestFile = async (
},
});

child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', stdOut);
child.stderr.on('data', stdOut);

Expand Down
Loading

0 comments on commit c7020ae

Please sign in to comment.