Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix React 16/17 runs #11

Merged
merged 5 commits into from
Apr 22, 2023
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
29 changes: 0 additions & 29 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,3 @@ jobs:

- name: Type Check
run: npx lerna run typecheck

integration:
strategy:
matrix:
node: [ 16, 18 ]
react: [ 16, 17, 18 ]
name: Integration testing (Node ${{ matrix.node }}, React ${{ matrix.react }})
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Setup packages
run: pnpm install

- name: Run tests
env:
REACT_VERSION: ${{ matrix.react }}
run: |
cd spec/main-suite
npm run integration:prepare
npm run integration:all
npm run integration:check
106 changes: 106 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Integration testing

on:
push:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
basic:
strategy:
matrix:
node: [ 16, 18 ]
react: [ 16, 17, 18 ]
name: Basic (Node ${{ matrix.node }}, React ${{ matrix.react }})
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Setup packages
run: pnpm install

- name: Run tests
env:
REACT_VERSION: ${{ matrix.react }}
run: |
cd spec/main-suite
npm run integration:prepare
npm run integration:all
npm run integration:check

npm:
name: Project using NPM
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Setup packages
run: pnpm install

- name: Prepare
run: |
cd spec/main-suite
npm run integration:prepare

- name: Install via NPM
run: |
cd spec/main-suite
rm -r node_modules
npm install

- name: Run perftool
run: |
cd spec/main-suite
npm run integration:npm

bad_ts-node:
name: Project with different TS-node version
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Setup packages
run: pnpm install

- name: Prepare
run: |
cd spec/main-suite
pnpm run integration:prepare

- name: Install bad ts-node version
run: |
cd spec/main-suite
pnpm add [email protected]

- name: Run perftool
run: |
cd spec/main-suite
pnpm run integration:unchanged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"conventional-commits"
]
},
"packageManager": "pnpm@8.2.0",
"packageManager": "pnpm@8.3.1",
"engines": {
"node": ">=18",
"pnpm": ">=8"
Expand Down
3 changes: 1 addition & 2 deletions packages/perftool/scripts/start-compare.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

set -ex
set -e

case "$(uname -s)" in
Darwin*)
Expand All @@ -21,7 +21,6 @@ OPTS="--loader $TS_NODE_ESM_PATH --experimental-specifier-resolution=node"

if [ -z "$PERFTOOL_DEBUG" ]; then
OPTS="$OPTS --no-warnings"
set -x
fi

NODE_OPTIONS=$OPTS TS_NODE_PROJECT="$PROJECT_DIR/tsconfig.json" TS_NODE_FILES=true node "$PROJECT_DIR/src/compare/index.ts" "$@"
3 changes: 1 addition & 2 deletions packages/perftool/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

set -ex
set -e

case "$(uname -s)" in
Darwin*)
Expand All @@ -21,7 +21,6 @@ OPTS="--loader $TS_NODE_ESM_PATH --experimental-specifier-resolution=node"

if [ -z "$PERFTOOL_DEBUG" ]; then
OPTS="$OPTS --no-warnings"
set -x
fi

NODE_OPTIONS=$OPTS TS_NODE_PROJECT="$PROJECT_DIR/tsconfig.json" TS_NODE_FILES=true node "$PROJECT_DIR/src/index.ts" "$@"
10 changes: 9 additions & 1 deletion packages/perftool/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Config } from '../config/common';
import { debug } from '../utils/logger';

import type { Task } from './measurement/types';
import { runTask, Subject } from './measurement/runner';
Expand All @@ -10,22 +11,29 @@ type CreatePerfToolClientParams<T extends Task<any, any>[]> = {
config: Config;
};

// TODO debug logging
export async function createPerfToolClient<T extends Task<any, any>[]>({
subjects,
tasks,
config,
}: CreatePerfToolClientParams<T>) {
debug('Perftool client created');
debug('Available subjects: ', subjects);
debug('Available tasks: ', tasks);
debug('Config: ', config);

const tests = await resolveTests({ tasks, subjects });
const resultPromises = [];

debug(`Running ${tests.length} tests`);
for (const { task, subject } of tests) {
const resultPromise = runTask({ task, subject, config });

resultPromises.push(resultPromise);
}

debug('Waiting for all tests to complete...');
const results = await Promise.all(resultPromises);

debug('All tests complete, calling window.finish');
await window.finish(results);
}
40 changes: 31 additions & 9 deletions packages/perftool/src/client/measurement/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Config } from '../../config/common';
import { getTaskConfig } from '../../config/task';
import BaseError from '../../utils/baseError';
import { defer } from '../../utils/deferred';
import { debug } from '../../utils/logger';

import { Task } from './types';

Expand Down Expand Up @@ -43,18 +44,39 @@ export function runTask<T extends Task<any, any>>({
const meta = { taskId: task.id, subjectId: subject.id };
const config = getTaskConfig(task, globalConfig);
const container = createContainer();
let isComplete = false;

debug('Running test\n', `TaskId: ${meta.taskId}\n`, `SubjectId: ${meta.subjectId}`);
debug('Task config: ', config);

return Promise.race([
task
.run({ Subject: subject.Component, config, container })
.then((result) => ({
...meta,
result,
}))
.catch((error: Error) => ({
...meta,
error: error.toString(),
})),
defer(globalConfig.taskWaitTimeout, () => ({ ...meta, error: new TimeoutError().toString() })),
.then((result) => {
debug(`Test ${meta.taskId}, ${meta.subjectId} complete. Result:`, result);

return {
...meta,
result,
};
})
.catch((error: Error) => {
debug(`Test ${meta.taskId}, ${meta.subjectId} failed. Error:`, error);

return {
...meta,
error: error.toString(),
};
})
.finally(() => {
isComplete = true;
}),
defer(globalConfig.taskWaitTimeout, () => {
if (!isComplete) {
debug(`Test ${meta.taskId}, ${meta.subjectId} timed out`);
}

return { ...meta, error: new TimeoutError().toString() };
}),
]);
}
6 changes: 5 additions & 1 deletion packages/perftool/src/clientEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import { getAllTasks } from './config/task';
import { createPerfToolClient } from './client';
import { Subject } from './client/measurement/runner';
import { subject as staticTaskSubject } from './stabilizers/staticTask';
import { setLogLevel } from './utils/logger';

// <IMPORT_MARK>

const config = ((v) => v)(
// <CONFIG_ARGS_MARK>
) as unknown as Config;

setLogLevel(config.logLevel);

const allTestSubjects: Subject[] = [
staticTaskSubject,
// <TEST_SUBJECT_MARK>
];

// TODO tasks in client config are serialized,
const allTasks = getAllTasks(config);

createPerfToolClient({
await createPerfToolClient({
config,
tasks: allTasks,
subjects: allTestSubjects,
Expand Down
9 changes: 8 additions & 1 deletion packages/perftool/src/config/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack, { Configuration as WebpackConfig } from 'webpack';
import { createRequire } from 'node:module';
import path from 'path';
import { fileURLToPath } from 'url';

import { debug } from '../utils/logger';

import { Config } from './common';

const require = createRequire(import.meta.url);
const dirname = path.dirname(fileURLToPath(import.meta.url));
const ownNodeModules = path.relative(process.cwd(), path.resolve(dirname, '../../node_modules'));

const defaultConfig: WebpackConfig = {
mode: 'production',
externals: ['fsevents'],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs'],
modules: ['node_modules', 'node_modules/@salutejs/perftool/node_modules'],
modules: ['node_modules', ownNodeModules],
fallback: {
'react-dom/client': false,
},
},
experiments: {
topLevelAwait: true,
Expand Down
Loading