Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
# dimension so flakiness.io keeps a separate history per Node
# version in the matrix.
FK_ENV_NODEJS: ${{ matrix.node }}
run: npm run test:unit:date -- --maxWorkers="$(nproc)"
run: npm run test:unit:date

compute-previous-wordpress-version:
name: Compute previous WordPress version
Expand Down
35 changes: 0 additions & 35 deletions bin/unit-test-date.sh

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"test:unit:vitest:update": "npm run --workspace @wordpress/unit-tests test:unit:vitest:update --",
"test:unit:vitest:watch": "npm run --workspace @wordpress/unit-tests test:unit:vitest:watch --",
"test:unit:routing": "npm run --workspace @wordpress/unit-tests test:unit:routing --",
"test:unit:date": "bash ./bin/unit-test-date.sh",
"test:unit:date": "npm run --workspace @wordpress/unit-tests test:unit:date",
Comment thread
manzoorwanijk marked this conversation as resolved.
Resolved
"test:unit:debug": "npm run --workspace @wordpress/unit-tests test:unit:debug --",
"test:unit:profile": "npm run --workspace @wordpress/unit-tests test:unit:profile --",
"test:unit:php:setup": "wp-env --config .wp-env.test.json start",
Expand Down
1 change: 1 addition & 0 deletions test/unit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"scripts": {
"test:unit": "vitest run --config vitest.config.mjs",
"test:unit:conventions": "node scripts/validate-vitest-conventions.mjs",
"test:unit:date": "node scripts/run-date-tests.mts",
"test:unit:vitest": "vitest run --config vitest.config.mjs",
"test:unit:vitest:shuffled": "npm run test:unit:vitest -- --sequence.shuffle.files --sequence.seed=80855",
"test:unit:vitest:update": "vitest run --config vitest.config.mjs --update=true",
Expand Down
61 changes: 61 additions & 0 deletions test/unit/scripts/run-date-tests.mts
Comment thread
manzoorwanijk marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { spawn } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolvePackageBin } from './resolve-package-bin.mjs';

const WORKSPACE_DIR = path.resolve(
path.dirname( fileURLToPath( import.meta.url ) ),
'..'
);
const VITEST_CONFIG = path.join( WORKSPACE_DIR, 'vitest.config.mjs' );
const TIMEZONES = [ 'EST', 'GMT', 'CET' ];
const LOCALES = [ 'en_US', 'ja_JP' ];

const vitestBin = resolvePackageBin( 'vitest' );

function runDateTests( timezone: string, locale: string ): Promise< boolean > {
const child = spawn(
process.execPath,
[ vitestBin, 'run', '--config', VITEST_CONFIG, 'packages/date' ],
{
cwd: WORKSPACE_DIR,
env: {
...process.env,
TZ: timezone,
LANG: locale,
// Use FK_ENV_* variables to define a dedicated Flakiness.io
// test environment.
// See https://docs.flakiness.io/ci/configuring-environments/
FK_ENV_TZ: timezone,
FK_ENV_LANG: locale,
FLAKINESS_OUTPUT_DIR: `flakiness-report-${ timezone }-${ locale }`,
},
stdio: 'inherit',
}
);

return new Promise( ( resolve, reject ) => {
child.on( 'error', reject );
child.on( 'close', ( code, signal ) =>
resolve( code === 0 && ! signal )
);
} );
}

const matrix = TIMEZONES.flatMap( ( timezone ) =>
LOCALES.map( ( locale ) => ( { timezone, locale } ) )
);
const results = await Promise.all(
matrix.map( ( { timezone, locale } ) => runDateTests( timezone, locale ) )
);
const failures = matrix.filter( ( entry, index ) => ! results[ index ] );

for ( const { timezone, locale } of failures ) {
process.stderr.write(
`Date tests failed with timezone = ${ timezone } and locale = ${ locale }\n`
);
}

if ( failures.length > 0 ) {
process.exitCode = 1;
}
2 changes: 1 addition & 1 deletion test/unit/scripts/validate-vitest-conventions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const vitestInfrastructure = [
nodir: true,
}
),
...globSync( 'test/unit/scripts/*.mjs', {
...globSync( 'test/unit/scripts/*.{mjs,mts}', {
cwd: ROOT_DIR,
nodir: true,
} ),
Expand Down
12 changes: 12 additions & 0 deletions test/unit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@wordpress/monorepo-tools/tsconfig/base.json",
"compilerOptions": {
"checkJs": false,
"noEmit": true,
"rootDir": ".",
"types": [ "node" ]
},
"include": [ "scripts/*.mts", "scripts/*.mjs" ],
"exclude": []
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
{ "path": "test/e2e" },
{ "path": "test/performance" },
{ "path": "test/storybook-playwright" },
{ "path": "test/unit" },
{ "path": "widgets" }
],
"files": []
Expand Down
Loading