Skip to content

Commit

Permalink
fix(Windows): adapt path sanitization and npx.cmd (#80)
Browse files Browse the repository at this point in the history
* chore(website): improve background

* chore(website): improve background

* chore: remove npx from scripts

* chore: remove npx from scripts

* chore: change multiple scripts from ";" to "&&"

* ci: fix env on Windows

* ci: remove docker from windows

* ci(windows): add Bun

* ci(windows): revert Bun

* ci(windows): better icon
  • Loading branch information
wellwelwel committed Mar 5, 2024
1 parent 05cb0da commit a30359d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: '🪟'
on:
push:
branches:
- 'main'
pull_request:
workflow_dispatch:

jobs:
node:
runs-on: windows-latest
timeout-minutes: 5
strategy:
fail-fast: false
name: Windows
steps:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'

- name: ➕ Actions - Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: 📦 Installing Dependencies
run: npm ci

- name: 🤹🏻‍♀️ Building the Project
run: npm run build

- name: 🔬 Node
run: npm run test
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
"description": "🐷 Poku makes testing easy for Node.js, Bun & Deno at the same time.",
"main": "./lib/index.js",
"scripts": {
"test": "npx tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
"test": "tsx --tsconfig ./tsconfig.test.json ./test/run.test.ts",
"pretest:c8": "npm run build",
"test:c8": "docker compose -f test/docker/docker-compose.c8.yml up",
"test:ci:c8": "npx c8 --include 'src/**' --exclude 'src/@types/**' --reporter=text --reporter=lcov npx tsx test/run.test.ts",
"test:ci:c8": "c8 --include 'src/**' --exclude 'src/@types/**' --reporter=text --reporter=lcov tsx test/run.test.ts",
"test:ci": "tsx ./test/ci.test.ts",
"test:node": "FILTER='node-' npm run test:ci",
"test:deno": "FILTER='deno-' npm run test:ci",
"test:bun": "FILTER='bun-' npm run test:ci",
"prebuild": "rm -rf ./lib ./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",
"build": "npx tsc; npx tsc -p tsconfig.test.json",
"postbuild": "npx tsx ./tools/compatibility/node.ts; chmod +x lib/bin/index.js; npm audit",
"eslint:checker": "npx eslint . --ext .js,.ts",
"eslint:fix": "npx eslint . --fix --config ./.eslintrc.json",
"lint:checker": "npm run eslint:checker; npm run prettier:checker",
"lint:fix": "npm run eslint:fix; npm run prettier:fix",
"prettier:checker": "npx prettier --check .",
"prettier:fix": "npx prettier --write .github/workflows/*.yml .",
"update": "npx npu; npm i; npm run lint:fix; npm audit"
"prebuild": "rm -rf ./lib ./ci",
"build": "tsc && tsc -p tsconfig.test.json",
"postbuild": "tsx ./tools/compatibility/node.ts && chmod +x lib/bin/index.js && npm audit",
"eslint:checker": "eslint . --ext .js,.ts",
"eslint:fix": "eslint . --fix --config ./.eslintrc.json",
"lint:checker": "npm run eslint:checker && npm run prettier:checker",
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
"prettier:checker": "prettier --check .",
"prettier:fix": "prettier --write .github/workflows/*.yml .",
"update": "npu && npm i && npm run lint:fix && npm audit"
},
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/list-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const sanitizePath = (input: string, ensureTarget?: boolean): string => {
const sanitizedPath = input
.replace(/[/\\]+/g, path.sep) // adapting slashes according to OS
.replace(/(\.\.(\/|\\|$))+/g, '') // ensure the current path level
.replace(/[<>:|^?*]+/g, ''); // removing unusual path characters
.replace(/[<>|^?*]+/g, ''); // removing unusual path characters

// Preventing absolute path access
return ensureTarget ? sanitizedPath.replace(/^[/\\]/, './') : sanitizedPath;
Expand Down
10 changes: 8 additions & 2 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ export const runTestFile = (
): Promise<boolean> =>
new Promise(async (resolve) => {
const runtimeOptions = runner(filePath, configs);
const runtime = runtimeOptions.shift();
const runtimeArguments =
const originalRuntime = runtimeOptions.shift();
let runtime = originalRuntime;
let runtimeArguments =
runtimeOptions.length > 1 ? [...runtimeOptions, filePath] : [filePath];

if (process.platform === 'win32' && originalRuntime === 'tsx') {
runtime = 'npx.cmd';
runtimeArguments = ['tsx', ...runtimeArguments];
}

const fileRelative = path.relative(process.cwd(), filePath);
const showLogs = !isQuiet(configs);
const showSuccess = isDebug(configs);
Expand Down
10 changes: 8 additions & 2 deletions test/integration/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { runner } from '../../src/helpers/runner.js';
// `/_.ts`: Simulate TypeScript file for Deno
const currentFile = typeof __filename === 'string' ? __filename : '/_.ts';
const runtimeOptions = runner(currentFile);
const runtime = runtimeOptions.shift()!;
const originalRuntime = runtimeOptions.shift();
let runtime = originalRuntime!;
const ext = runtime === 'node' ? 'js' : 'ts';

const executeCLI = (args: string[]): Promise<string> =>
new Promise((resolve, reject) => {
const runtimeArguments =
let runtimeArguments =
runtimeOptions.length > 1 ? [...runtimeOptions, ...args] : [...args];

if (process.platform === 'win32' && originalRuntime === 'tsx') {
runtime = 'npx.cmd';
runtimeArguments = ['tsx', ...runtimeArguments];
}

const childProcess = spawn(runtime, runtimeArguments, {
shell: false,
cwd: process.cwd(),
Expand Down
4 changes: 4 additions & 0 deletions website/src/css/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ pre[class*='language-'] {
no-repeat;
}

html[data-theme='light'] {
background-color: #eff2f9;
}

html[data-theme='dark'] {
background-color: #161927;
color: #b9bfdc;
Expand Down

0 comments on commit a30359d

Please sign in to comment.