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

chore: Upgrade to TypeScript 5.6, eslint 8, and some more #400

Merged
merged 4 commits into from
Dec 13, 2024
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
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ set -euo pipefail

exec < /dev/tty
npm run copy-shared-files
npx lint-staged
12 changes: 12 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
link-workspace-packages = true
shared-workspace-lockfile = true
hoist = false

# By default, PNPM hoists eslint and prettier to the workspace root, but that may causes issues
# with this workspace, as some samples have completely different versions of these packages, or
# depends on incompatible plugins.
public-hoist-pattern = []

# The monorepo sample uses postcss with an external configuration file that refers to plugins by
# their package name, rather than passing objects. That doesn't work with PNPM's strict node_modules
# structure. To work around this, hoist all postcss-* packages.
# FIXME: Can't we do something equivalent at the project-level instead?
public-hoist-pattern[] = postcss-*
23 changes: 8 additions & 15 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
.prettierignore
.husky/
node_modules
build
lib
.next
.vscode
protobufs/protos/json-module.js
protobufs/protos/root.d.ts
.scripts/list-of-samples.json
package-lock.json
pnpm-lock.yaml
# Ignore everything by default, except for the files and folders listed below
*

!.devcontainer/
!.github/

nestjs-exchange-rates/dist
!.scripts/
.scripts/list-of-samples.json

.github/workflows/ci.yml
dist.css
!./package.json
40 changes: 0 additions & 40 deletions .scripts/wait-on-temporal.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion .shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"version": "4.4.2",
"version": "5.6.3",
"compilerOptions": {
"lib": ["es2021"],
"declaration": true,
Expand Down
22 changes: 12 additions & 10 deletions activities-cancellation-heartbeating/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"scripts": {
"build": "tsc --build",
"build.watch": "tsc --build --watch",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint .",
"start": "ts-node src/worker.ts",
"start.watch": "nodemon src/worker.ts",
Expand All @@ -26,16 +28,16 @@
"@temporalio/workflow": "^1.11.5"
},
"devDependencies": {
"@tsconfig/node18": "^1.0.3",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^22.9.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-deprecation": "^1.2.1",
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.9.5"
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"nodemon": "^3.1.7",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function cancelTimerAltImpl(): Promise<void> {
// @@@SNIPSTART typescript-handle-external-workflow-cancellation-while-activity-running
export async function handleExternalWorkflowCancellationWhileActivityRunning(
url: string,
data: unknown
data: unknown,
): Promise<void> {
try {
await httpPostJSON(url, data);
Expand Down
2 changes: 1 addition & 1 deletion activities-cancellation-heartbeating/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"version": "4.4.2",
"version": "5.6.3",
"compilerOptions": {
"lib": ["es2021"],
"declaration": true,
Expand Down
22 changes: 12 additions & 10 deletions activities-dependency-injection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"scripts": {
"build": "tsc --build",
"build.watch": "tsc --build --watch",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint .",
"start": "ts-node src/worker.ts",
"start.watch": "nodemon src/worker.ts",
Expand All @@ -26,16 +28,16 @@
"@temporalio/workflow": "^1.11.5"
},
"devDependencies": {
"@tsconfig/node18": "^1.0.3",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^22.9.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-deprecation": "^1.2.1",
"nodemon": "^2.0.12",
"prettier": "^2.8.8",
"ts-node": "^10.2.1",
"typescript": "^4.9.5"
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"nodemon": "^3.1.7",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
2 changes: 1 addition & 1 deletion activities-dependency-injection/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"version": "4.4.2",
"version": "5.6.3",
"compilerOptions": {
"lib": ["es2021"],
"declaration": true,
Expand Down
22 changes: 12 additions & 10 deletions activities-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"build": "tsc --build",
"build.watch": "tsc --build --watch",
"jest": "jest",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint .",
"start": "ts-node src/worker.ts",
"start.watch": "nodemon src/worker.ts",
Expand Down Expand Up @@ -35,28 +37,28 @@
"devDependencies": {
"@temporalio/nyc-test-coverage": "^1.11.5",
"@temporalio/testing": "^1.11.5",
"@tsconfig/node18": "^1.0.3",
"@tsconfig/node18": "^18.2.4",
"@types/jest": "^27.5.1",
"@types/mocha": "8.x",
"@types/node": "^22.9.1",
"@types/node-fetch": "^2.5.12",
"@types/sinon": "^10.0.4",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-deprecation": "^1.2.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-deprecation": "^3.0.0",
"jest": "^28.1.0",
"mocha": "8.x",
"nodemon": "^2.0.12",
"nodemon": "^3.1.7",
"nyc": "15.1.0",
"prettier": "^2.8.8",
"prettier": "^3.4.2",
"sinon": "^11.1.2",
"source-map-support": "^0.5.21",
"ts-jest": "^28.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.9.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"uuid": "^8.3.2",
"webpack": "5.96.1"
}
Expand Down
93 changes: 36 additions & 57 deletions activities-examples/src/mocha/workflows.test.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,81 @@
import { ActivityFailure, ApplicationFailure, Client, WorkflowFailedError } from '@temporalio/client';
import { Runtime, DefaultLogger, Worker } from '@temporalio/worker';
import { ActivityFailure, ApplicationFailure, WorkflowFailedError } from '@temporalio/client';
import { Runtime, DefaultLogger, Worker, WorkerOptions } from '@temporalio/worker';
import { TestWorkflowEnvironment } from '@temporalio/testing';
import assert from 'assert';
import axios from 'axios';
import { after, afterEach, before, describe, it } from 'mocha';
import { after, before, describe, it } from 'mocha';
import sinon from 'sinon';
import { v4 as uuid } from 'uuid';
import * as activities from '../activities';
import { httpWorkflow } from '../workflows';
import * as activities from '../activities';
import { WorkflowCoverage } from '@temporalio/nyc-test-coverage';

const workflowCoverage = new WorkflowCoverage();

describe('example workflow', async function () {
let shutdown: () => Promise<void>;
let execute: () => ReturnType<typeof httpWorkflow>;
let getClient: () => Client;

this.slow(10_000);
this.timeout(20_000);

let env: TestWorkflowEnvironment;

before(async function () {
// Filter INFO log messages for clearer test output
Runtime.install({ logger: new DefaultLogger('WARN') });
const env = await TestWorkflowEnvironment.createLocal();
env = await TestWorkflowEnvironment.createLocal();
});

after(async () => {
await env.teardown();
workflowCoverage.mergeIntoGlobalCoverage();
});

async function executeWithWorker(workerOptions: Pick<WorkerOptions, 'activities'>) {
const taskQueue = `test-activities-${uuid()}`;

const worker = await Worker.create(
workflowCoverage.augmentWorkerOptions({
...workerOptions,
activities: { ...activities, ...workerOptions.activities },
connection: env.nativeConnection,
taskQueue: 'test-activities',
taskQueue,
workflowsPath: require.resolve('../workflows'),
activities,
})
}),
);

const runPromise = worker.run();
shutdown = async () => {
worker.shutdown();
await runPromise;
await env.teardown();
};
getClient = () => env.client;
});

beforeEach(() => {
const client = getClient();

execute = () =>
client.workflow.execute(httpWorkflow, {
taskQueue: 'test-activities',
return await worker.runUntil(async () =>
env.client.workflow.execute(httpWorkflow, {
taskQueue,
workflowExecutionTimeout: 10_000,
// Use random ID because ID is meaningless for this test
workflowId: `test-${uuid()}`,
});
});

after(async () => {
await shutdown();
});

after(() => {
workflowCoverage.mergeIntoGlobalCoverage();
});

afterEach(() => {
sinon.restore();
});
}),
);
}

it('returns correct result', async () => {
const result = await execute();
const result = await executeWithWorker({});
assert.equal(result, 'The answer is 42');
});

it('retries one failure', async () => {
// Make the first request fail, but subsequent requests succeed
let numCalls = 0;
sinon.stub(axios, 'get').callsFake(() => {
if (numCalls++ === 0) {
return Promise.reject(new Error('first error'));
}
return Promise.resolve({ data: { args: { answer: '88' } } });
});
const fakeMakeHTTPRequest = sinon.stub();
fakeMakeHTTPRequest.onFirstCall().rejects(new Error('example error'));
fakeMakeHTTPRequest.resolves('88');

const result = await executeWithWorker({ activities: { makeHTTPRequest: fakeMakeHTTPRequest } });

const result = await execute();
assert.equal(result, 'The answer is 88');
assert.equal(numCalls, 2);
assert.equal(fakeMakeHTTPRequest.callCount, 2);
});

it('bubbles up activity errors', async () => {
sinon.stub(axios, 'get').callsFake(() => Promise.reject(new Error('example error')));
const fakeMakeHTTPRequest = sinon.stub().rejects(new Error('example error'));

await assert.rejects(
execute,
executeWithWorker({ activities: { makeHTTPRequest: fakeMakeHTTPRequest } }),
(err: unknown) =>
err instanceof WorkflowFailedError &&
err.cause instanceof ActivityFailure &&
err.cause.cause instanceof ApplicationFailure &&
err.cause.cause.message === 'example error'
err.cause.cause.message === 'example error',
);
});
});
2 changes: 1 addition & 1 deletion activities-examples/src/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('httpWorkflow with mock activity', async () => {
activities: {
makeHTTPRequest: async () => '99',
},
})
}),
);

await worker.runUntil(async () => {
Expand Down
Loading
Loading