Skip to content

Commit

Permalink
[patch] fix tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Sep 11, 2024
1 parent 6898db7 commit 15b39e7
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 144 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,29 @@ concurrency:
cancel-in-progress: true

jobs:
build:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
# handle NPM / Node.js repeatedly bricking their npm setup on Windows
# Note that this won't work if it uses --no-save
- if: runner.os == 'Windows'
shell: bash
run: |
npm install npm
npm i npm
# format package.json is to account for the above `npm i npm` command
- name: run test
shell: bash
run: |
npm ci
npx playwright install --with-deps
npm run format package.json
npm run test:all
297 changes: 221 additions & 76 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/mono-repo-root",
"version": "13.3.10",
"version": "13.3.11",
"private": true,
"type": "module",
"workspaces": [
Expand Down Expand Up @@ -58,6 +58,7 @@
"node": ">=22"
},
"overrides": {
"playwright": "1.46.1",
"virmator": "*"
}
}
6 changes: 3 additions & 3 deletions packages/compile/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/compile",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default TS compile plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -33,12 +33,12 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"run-time-assertions": "^1.5.2"
},
"devDependencies": {
"@types/node": "^22.5.4",
"@virmator/plugin-testing": "^13.3.10",
"@virmator/plugin-testing": "^13.3.11",
"c8": "^10.1.2",
"chalk": "^5.3.0",
"concurrently": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/compile/src/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(virmatorCompilePlugin.name, () => {
* are stable.
*/
if (logType === LogOutputType.standard) {
return arg.replace(/ Version.+/, '');
return arg;
}
return arg;
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/core",
"version": "13.3.10",
"version": "13.3.11",
"description": "Shared core functionality for all virmator plugins and the virmator CLI.",
"keywords": [
"automation",
Expand Down
4 changes: 2 additions & 2 deletions packages/deps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/deps",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default TS deps plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"mri": "^1.2.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/docs",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default TS docs plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"chalk": "^5.3.0",
"mri": "^1.2.0",
"run-time-assertions": "^1.5.2"
Expand Down
12 changes: 9 additions & 3 deletions packages/docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {ChalkInstance} from 'chalk';
import mri from 'mri';
import {basename, join} from 'node:path';
import {pathToFileURL} from 'node:url';
import type * as Typedoc from 'typedoc';

/** A virmator plugin for checking and generating documentation. */
Expand Down Expand Up @@ -160,9 +161,14 @@ export const virmatorDocsPlugin = defineVirmatorPlugin(
}

// dynamic imports are not branches
/* node:coverage ignore next 2 */
const config = (await import(join(packageDir, configs.docs.configs.typedoc.copyToPath)))
.typeDocConfig as Typedoc.TypeDocOptions;
/* node:coverage ignore next 7 */
const config = (
await import(
pathToFileURL(
join(packageDir, configs.docs.configs.typedoc.copyToPath),
).toString()
)
).typeDocConfig as Typedoc.TypeDocOptions;

await runTypedoc({
checkOnly,
Expand Down
4 changes: 2 additions & 2 deletions packages/format/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/format",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default format plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"mri": "^1.2.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/frontend",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default frontend plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"mri": "^1.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/frontend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe(virmatorFrontendPlugin.name, () => {
dir,
{
logTransform(logType, log) {
return log.replace(/built in [\dm]+s/, 'built');
return log.replace(/built in [\d.m]+s/g, 'built');
},
},
);
Expand Down
5 changes: 4 additions & 1 deletion packages/frontend/src/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {defineVirmatorPlugin, NpmDepType, PackageType, VirmatorEnv} from '@virma
import mri from 'mri';
import {cp, rm} from 'node:fs/promises';
import {join, relative, resolve} from 'node:path';
import {pathToFileURL} from 'node:url';
import type {UserConfig} from 'vite';

/** A virmator plugin for running and building frontend packages. */
Expand Down Expand Up @@ -109,7 +110,9 @@ export const virmatorFrontendPlugin = defineVirmatorPlugin(
usedCommands.frontend?.subCommands.build || usedCommands.frontend?.subCommands.preview;
const configPath = args.config || configs.frontend.configs.vite.fullCopyToPath;

const viteConfig = await ((await import(configPath)).default as MaybePromise<UserConfig>);
const viteConfig = await ((
await import(pathToFileURL(configPath).toString())
).default as MaybePromise<UserConfig>);

const rootDir: string = viteConfig.root ? resolve(cwd, viteConfig.root) : cwd;
const outDir: string = resolve(rootDir, viteConfig.build?.outDir || 'dist');
Expand Down
4 changes: 2 additions & 2 deletions packages/help/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/help",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default help plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"run-time-assertions": "^1.5.2"
},
"devDependencies": {
Expand Down
7 changes: 5 additions & 2 deletions packages/init/configs/github/workflows/tests-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
# handle NPM / Node.js repeatedly bricking their npm setup on Windows
# Note that this won't work if it uses --no-save
- if: runner.os == 'Windows'
shell: bash
run: |
npm install npm
npm i npm
# format package.json is to account for the above `npm i npm` command
- name: run test
shell: bash
run: |
npm ci
npm run format package.json
npm run test:all
7 changes: 5 additions & 2 deletions packages/init/configs/github/workflows/tests-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
# handle NPM / Node.js repeatedly bricking their npm setup on Windows
# Note that this won't work if it uses --no-save
- if: runner.os == 'Windows'
shell: bash
run: |
npm install npm
npm i npm
# format package.json is to account for the above `npm i npm` command
- name: run test
shell: bash
run: |
npm ci
npx playwright install --with-deps
npm run format package.json
npm run test:all
4 changes: 2 additions & 2 deletions packages/init/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/init",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default init plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"simple-git": "^3.26.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/lint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/lint",
"version": "13.3.10",
"version": "13.3.11",
"description": "Default ESLint linting plugin for virmator.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"mri": "^1.2.0"
},
"devDependencies": {
Expand Down
17 changes: 15 additions & 2 deletions packages/lint/src/lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {safeMatch} from '@augment-vir/common';
import {testPlugin} from '@virmator/plugin-testing';
import {join, resolve} from 'node:path';
import {basename, join, resolve} from 'node:path';
import {describe, it, TestContext} from 'node:test';
import {virmatorLintPlugin} from './lint.js';

Expand All @@ -12,7 +13,19 @@ describe(virmatorLintPlugin.name, () => {
cwd: string,
extraCommand = '',
) {
await testPlugin(shouldPass, context, virmatorLintPlugin, `lint ${extraCommand}`, cwd);
await testPlugin(shouldPass, context, virmatorLintPlugin, `lint ${extraCommand}`, cwd, {
logTransform(logType, arg) {
const [
,
fileName,
] = safeMatch(arg, /\s(\S*packages[/\\].+?\.ts)\s/);

if (fileName) {
return arg.replace(fileName, basename(fileName));
}
return arg;
},
});
}

it('lints a valid project', async (context) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/lint/src/lint.test.ts.snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exports[`Lint > fixes an invalid project 1`] = `
{
"logs": {
"stdout": "Copied eslint.config.mjs\\nInstalling [email protected] [email protected] [email protected] @eslint/[email protected] @eslint/[email protected] @stylistic/[email protected] [email protected] @stylistic/[email protected] @typescript-eslint/[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]...\\n> npx eslint --fix .\\n\\npackages/lint/test-files/bad-repo/src/a.ts\\n 3:8 error Async function 'doThing' has no 'await' expression @typescript-eslint/require-await\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n\\n✖ 2 problems (2 errors, 0 warnings)\\n",
"stdout": "Copied eslint.config.mjs\\nInstalling [email protected] [email protected] [email protected] @eslint/[email protected] @eslint/[email protected] @stylistic/[email protected] [email protected] @stylistic/[email protected] @typescript-eslint/[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]...\\n> npx eslint --fix .\\n\\na.ts\\n 3:8 error Async function 'doThing' has no 'await' expression @typescript-eslint/require-await\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n\\n✖ 2 problems (2 errors, 0 warnings)\\n",
"stderr": "lint failed."
},
"cwd": "packages/lint/test-files/bad-repo",
Expand Down Expand Up @@ -34,7 +34,7 @@ exports[`Lint > lints a valid project 1`] = `
exports[`Lint > lints an invalid project 1`] = `
{
"logs": {
"stdout": "Copied eslint.config.mjs\\nInstalling [email protected] [email protected] [email protected] @eslint/[email protected] @eslint/[email protected] @stylistic/[email protected] [email protected] @stylistic/[email protected] @typescript-eslint/[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]...\\n> npx eslint .\\n\\npackages/lint/test-files/bad-repo/src/a.ts\\n 3:8 error Async function 'doThing' has no 'await' expression @typescript-eslint/require-await\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error This assertion is unnecessary since it does not change the type of the expression @typescript-eslint/no-unnecessary-type-assertion\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error This assertion is unnecessary since it does not change the type of the expression @typescript-eslint/no-unnecessary-type-assertion\\n 4:12 error Forbidden extra non-null assertion @typescript-eslint/no-extra-non-null-assertion\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error Forbidden extra non-null assertion @typescript-eslint/no-extra-non-null-assertion\\n\\n✖ 8 problems (8 errors, 0 warnings)\\n 4 errors and 0 warnings potentially fixable with the \`--fix\` option.\\n",
"stdout": "Copied eslint.config.mjs\\nInstalling [email protected] [email protected] [email protected] @eslint/[email protected] @eslint/[email protected] @stylistic/[email protected] [email protected] @stylistic/[email protected] @typescript-eslint/[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]...\\n> npx eslint .\\n\\na.ts\\n 3:8 error Async function 'doThing' has no 'await' expression @typescript-eslint/require-await\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error This assertion is unnecessary since it does not change the type of the expression @typescript-eslint/no-unnecessary-type-assertion\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error This assertion is unnecessary since it does not change the type of the expression @typescript-eslint/no-unnecessary-type-assertion\\n 4:12 error Forbidden extra non-null assertion @typescript-eslint/no-extra-non-null-assertion\\n 4:12 error Forbidden non-null assertion @typescript-eslint/no-non-null-assertion\\n 4:12 error Forbidden extra non-null assertion @typescript-eslint/no-extra-non-null-assertion\\n\\n✖ 8 problems (8 errors, 0 warnings)\\n 4 errors and 0 warnings potentially fixable with the \`--fix\` option.\\n",
"stderr": "lint failed."
},
"cwd": "packages/lint/test-files/bad-repo",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virmator/plugin-testing",
"version": "13.3.10",
"version": "13.3.11",
"description": "Testing for virmator plugins.",
"keywords": [
"virmator",
Expand Down Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"@augment-vir/common": "^29.3.0",
"@augment-vir/node-js": "^29.3.0",
"@virmator/core": "^13.3.10",
"@virmator/core": "^13.3.11",
"cli-args-vir": "^0.0.3",
"run-time-assertions": "^1.5.2",
"type-fest": "^4.26.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-testing/src/augments/fs/dir-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function readAllDirContents(
excludeList?: ReadonlyArray<string | RegExp> | undefined;
},
): Promise<DirContents> {
const fileNames = await readdir(dir);
const fileNames = (await readdir(dir)).sort();

const allFileContents = await Promise.all(
fileNames.map(async (fileName) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-testing/src/test-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function testPlugin(

const result: TestPluginResult = {
logs: mapObjectValues(logs, (logType, logs) => {
return toPosixPath(logTransform(logType, logs.join('\n')));
return toPosixPath(logTransform(logType, logs.join('\n'))).replaceAll('\r', '');
}),
cwd: toPosixPath(relative(monoRepoDir, cwd)),
contentsDiff,
Expand Down
Loading

0 comments on commit 15b39e7

Please sign in to comment.