Skip to content

Commit

Permalink
Maintenance tasks (#1950)
Browse files Browse the repository at this point in the history
* tweak test concurrency options

* update CI config and test matrix

* Further optimization

* name all steps in CI; fix node version check for new nightly format

* More CI maint

* upgrade yarn, fix cache issue when installing from tarball into ./tests/node_modules

* Fix swc bug, since swc supports `target: esnext` now

* Fix test failure due to new TS's `allowImportingTsExtensions` diagnostic

* update yarn lockfile

* bump another gh action version

* Fix allImportingTsExtensions test

* Fix another test failure due to allImportingTsExtensions

* remove duplicated tests

* Fix failing @tsconfig/bases test

* fmt

* cleanup previous fix, and fix diagnostic test failing on 4.2

* make it less flaky?

* improve some tests to be faster, rely less on long pauses which fail on CI

* fix failing repl tests

* oops
  • Loading branch information
cspotcode committed Feb 6, 2023
1 parent 8b09d49 commit 02aee9c
Show file tree
Hide file tree
Showing 26 changed files with 1,222 additions and 1,201 deletions.
141 changes: 44 additions & 97 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -18,27 +18,31 @@ jobs:
runs-on: ubuntu-latest
steps:
# checkout code
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
# install node
- name: Use Node.js 18
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 18
- name: Get cache directory
id: get-cache-directory
run: |
yarn config get cacheFolder
echo "::set-output name=path::$( yarn config get cacheFolder )"
echo "path=$( yarn config get cacheFolder )" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.get-cache-directory.outputs.path }}
key: yarn-cache-packaging-${{ hashFiles('yarn.lock') }}
restore-keys: yarn-cache-packaging-
# lint, build, test
- run: yarn install --immutable
- run: yarn lint
- run: yarn build
- name: Install dependencies
run: yarn install --immutable
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Upload package artifact
uses: actions/upload-artifact@v1
with:
Expand All @@ -57,145 +61,88 @@ jobs:
matrix:
os: [ubuntu, windows]
# Don't forget to add all new flavors to this list!
flavor: [2, 3, 4, 6, 8, 9, 10, 11]
flavor: [1, 2, 3, 4, 5]
include:
# Node 14.13.0
# To test ESM builtin module resolution immediately before a node behavioral change: https://github.com/TypeStrong/ts-node/issues/1130
# - flavor: 1
# node: 14.13.0
# nodeFlag: 14_13_0
# typescript: latest
# typescriptFlag: latest
# Node 14
- flavor: 2
node: 14
nodeFlag: 14
typescript: latest
typescriptFlag: latest
- flavor: 3
node: 14
nodeFlag: 14
typescript: 4.0
typescriptFlag: 4_0
- flavor: 4
node: 14
nodeFlag: 14
typescript: next
typescriptFlag: next
# Node 16
# Node 16.11.1
# Earliest version that supports old ESM Loader Hooks API: https://github.com/TypeStrong/ts-node/pull/1522
# - flavor: 5
# node: 16.11.1
# nodeFlag: 16_11_1
# typescript: latest
# typescriptFlag: latest
- flavor: 6
- flavor: 1
node: 16
nodeFlag: 16
typescript: latest
typescriptFlag: latest
downgradeNpm: true
# - flavor: 7
# node: 16
# nodeFlag: 16
# typescript: 4.0
# typescriptFlag: 4_0
# downgradeNpm: true
- flavor: 8
- flavor: 2
node: 16
nodeFlag: 16
typescript: next
typescriptFlag: next
downgradeNpm: true
typescript: 4.2
typescriptFlag: 4_2
# Node 18
- flavor: 9
- flavor: 3
node: 18
nodeFlag: 18
typescript: latest
typescriptFlag: latest
downgradeNpm: true
- flavor: 10
- flavor: 4
node: 18
nodeFlag: 18
typescript: next
typescriptFlag: next
downgradeNpm: true
# Node nightly
- flavor: 11
node: nightly
nodeFlag: nightly
- flavor: 5
node: 19-nightly
nodeFlag: 19_nightly
typescript: latest
typescriptFlag: latest
downgradeNpm: true
steps:
# checkout code
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
# install node
- name: Use Node.js ${{ matrix.node }}
if: matrix.node != 'nightly'
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Use Node.js 16, will be subsequently overridden by download of nightly
if: matrix.node == 'nightly'
uses: actions/setup-node@v1
with:
node-version: 16
- name: Download Node.js nightly
if: matrix.node == 'nightly' && matrix.os == 'ubuntu'
run: |
export N_PREFIX=$(pwd)/n
npm install -g n
n nightly
sudo cp "${N_PREFIX}/bin/node" "$(which node)"
node --version
- name: Download Node.js nightly
if: matrix.node == 'nightly' && matrix.os == 'windows'
run: |
$version = (Invoke-WebRequest https://nodejs.org/download/nightly/index.json | ConvertFrom-json)[0].version
$url = "https://nodejs.org/download/nightly/$version/win-x64/node.exe"
$targetPath = (Get-Command node.exe).Source
Invoke-WebRequest -Uri $url -OutFile $targetPath -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome)
node --version
# lint, build, test
- name: Get cache directory
id: get-cache-directory
run: |
yarn config get cacheFolder
echo "::set-output name=path::$( yarn config get cacheFolder )"
echo "path=$( yarn config get cacheFolder )" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ matrix.os != 'windows' }}
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.get-cache-directory.outputs.path }}
key: yarn-cache-${{ matrix.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: yarn-cache-${{matrix.os }}-
- run: yarn install --immutable --mode=skip-build
- name: Upload yarn logs
if: ${{ failure() }}
uses: actions/upload-artifact@v1
with:
name: yarn-logs
path: yarn-error.log
- run: yarn build-tsc
- name: Install dependencies
run: yarn install --immutable --mode=skip-build
- name: Build tests
run: yarn build-tsc
- name: Download package artifact
uses: actions/download-artifact@v1
with:
name: ts-node-packed.tgz
path: tests/
- run: yarn add -D typescript@${{ matrix.typescript }}
- run: yarn test-cov
- name: Upload yarn logs
- name: Install typescript version to test against
run: yarn add -D typescript@${{ matrix.typescript }}
- name: Test
run: yarn test-cov
- name: Check for yarn logs
id: check-yarn-logs-exist
if: ${{ failure() }}
uses: andstor/file-existence-action@v2
with:
files: yarn-error.log
- name: Upload yarn logs
if: ${{ failure() && steps.check-yarn-logs-exist.outputs.files_exists == 'true' }}
uses: actions/upload-artifact@v1
with:
name: yarn-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }}
path: yarn-error.log
- run: yarn coverage-report
- name: Coverage Report
run: yarn coverage-report
if: ${{ always() }}
- name: Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.os }},node_${{ matrix.nodeFlag }},typescript_${{ matrix.typescriptFlag }}
6 changes: 3 additions & 3 deletions .github/workflows/website.yml
Expand Up @@ -12,10 +12,10 @@ jobs:
# checkout code
- uses: actions/checkout@v2
# install node
- name: Use Node.js 14
uses: actions/setup-node@v1
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
# Render typedoc
- run: npm install && npx typedoc
# Render docusaurus and deploy website
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,3 +16,4 @@ npm-debug.log
/yarn-error.log
/.yarn/install-state.gz
/tests/.yarn/install-state.gz
/tests/.yarn/cache
783 changes: 0 additions & 783 deletions .yarn/releases/yarn-3.2.2.cjs

This file was deleted.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .yarnrc.yml
@@ -1,5 +1,7 @@
enableGlobalCache: true

nmHoistingLimits: workspaces

nmMode: hardlinks-global

nodeLinker: node-modules
Expand All @@ -8,6 +10,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
spec: .yarn/plugins/@yarnpkg/plugin-compat.cjs

yarnPath: .yarn/releases/yarn-3.2.2.cjs

nmHoistingLimits: workspaces
yarnPath: .yarn/releases/yarn-3.4.1.cjs
2 changes: 1 addition & 1 deletion ava.config.cjs
Expand Up @@ -17,7 +17,7 @@ module.exports = {
require: ['./src/test/remove-env-var-force-color.js'],
nodeArguments: ['--loader', './src/test/test-loader.mjs', '--no-warnings'],
timeout: '300s',
concurrency: 1,
concurrency: 4,
};

{
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -109,8 +109,8 @@
"homepage": "https://typestrong.org/ts-node",
"devDependencies": {
"@microsoft/api-extractor": "^7.19.4",
"@swc/core": ">=1.2.205",
"@swc/wasm": ">=1.2.205",
"@swc/core": ">=1.3.32",
"@swc/wasm": ">=1.3.32",
"@types/diff": "^4.0.2",
"@types/lodash": "^4.14.151",
"@types/node": "13.13.5",
Expand Down Expand Up @@ -175,5 +175,5 @@
"node": "18.1.0",
"npm": "6.14.15"
},
"packageManager": "yarn@3.2.2"
"packageManager": "yarn@3.4.1"
}
6 changes: 4 additions & 2 deletions src/test/ci-node-and-ts-versions.spec.ts
Expand Up @@ -14,8 +14,10 @@ test.suite('Confirm node and typescript versions on CI', (test) => {
const actualVersion = process.versions.node;
t.log({ expectedVersion, actualVersion });
expect(expectedVersion).toBeDefined();
if (expectedVersion === 'nightly') {
expect(actualVersion).toMatch('nightly');
const major = expectedVersion.match(/^(\d+)-nightly$/)?.[1];
if (major != null) {
expect(actualVersion).toMatch(new RegExp('^' + major));
expect(actualVersion).toMatch('-nightly');
} else {
expect(semver.satisfies(actualVersion, expectedVersion)).toBe(true);
}
Expand Down
64 changes: 24 additions & 40 deletions src/test/diagnostics.spec.ts
Expand Up @@ -8,60 +8,44 @@ const test = context(ctxTsNode);
test.suite('TSError diagnostics', ({ context }) => {
const test = context(
once(async (t) => {
// Locking to es2021, because es2022 -- default in @tsconfig/bases for node18 --
// changes this diagnostic to be a composite "No overload matches this call."
// Locking to es2020, because:
// 1) es2022 -- default in @tsconfig/bases for node18 -- changes this diagnostic
// to be a composite "No overload matches this call."
// 2) TS 4.2 doesn't support es2021 or higher
const service = t.context.tsNodeUnderTest.create({
compilerOptions: { target: 'es5', lib: ['es2021'] },
compilerOptions: { target: 'es5', lib: ['es2020'] },
skipProject: true,
});
try {
service.compile('new Error(123)', 'test.ts');
} catch (err) {
return { service, err };
return { err: err as TSError };
}
return { service, err: undefined };
return { err: undefined };
})
);

const diagnosticCode = 2345;
const diagnosticMessage =
"Argument of type 'number' " +
"is not assignable to parameter of type 'string'.";
const diagnosticErrorMessage = `TS${diagnosticCode}: ${diagnosticMessage}`;
/Argument of type '.*?' is not assignable to parameter of type 'string( \| undefined)?'./;
const diagnosticErrorMessage =
/TS2345: Argument of type '.*?' is not assignable to parameter of type 'string( \| undefined)?'./;

const cwdBefore = process.cwd();
test('should throw errors', ({ log, context: { err, service } }) => {
log({
version: ts.version,
serviceVersion: service.ts.version,
cwdBefore,
cwd: process.cwd(),
configFilePath: service.configFilePath,
config: service.config.options,
});
test('should throw errors', (t) => {
const { err } = t.context;
expect(err).toBeDefined();
expect((err as Error).message).toMatch(diagnosticErrorMessage);
});

test('should throw errors with diagnostic text', ({ context: { err } }) => {
expect((err as TSError).diagnosticText).toMatch(diagnosticErrorMessage);
});

test('should throw errors with diagnostic codes', ({ context: { err } }) => {
expect((err as TSError).diagnosticCodes).toEqual([2345]);
});

test('should throw errors with complete diagnostic information', ({
context: { err },
}) => {
const diagnostics = (err as TSError).diagnostics;

expect(diagnostics).toHaveLength(1);
expect(diagnostics[0]).toMatchObject({
code: 2345,
start: 10,
length: 3,
messageText: expect.stringMatching(diagnosticMessage),
expect(err!).toMatchObject({
message: expect.stringMatching(diagnosticErrorMessage),
diagnosticText: expect.stringMatching(diagnosticErrorMessage),
diagnosticCodes: [diagnosticCode],
diagnostics: [
{
code: diagnosticCode,
start: 10,
length: 3,
messageText: expect.stringMatching(diagnosticMessage),
},
],
});
});
});

0 comments on commit 02aee9c

Please sign in to comment.