Skip to content

Commit 0faf586

Browse files
authored
refact: use yarn pack to generate package for testing (#216)
Use the generated tarball from `yarn pack` when running the tests. This way the dependencies resolution is more accurate to the user environment and we avoid some "hacks" using link: and file: Replaced npx calls with yarn We might not need this workaround in yarn berry #199
1 parent faedb50 commit 0faf586

20 files changed

+278
-1882
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ jobs:
3535
cache: yarn
3636
cache-dependency-path: "**/yarn.lock"
3737

38-
- run: yarn install --frozen-lockfile
38+
- run: yarn install
3939

4040
- run: yarn build
4141

42+
- name: Install dependencies for testing
43+
run: |
44+
yarn install-ttp
45+
yarn install
46+
working-directory: test
47+
4248
- name: Test
49+
working-directory: test
4350
run: yarn test --runInBand=false --maxWorkers=2 --workerIdleMemoryLimit=2GB # https://github.com/facebook/jest/issues/11956
4451
env:
4552
NODE_OPTIONS: --max_old_space_size=4096

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ fabric.properties
7575

7676
# Editor-based Rest Client
7777
.idea/httpRequests
78+
79+
test/out.tgz

package.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
"scripts": {
88
"compile": "tsc",
99
"build": "yarn run clean && yarn run compile",
10-
"test": "jest",
10+
"test": "yarn --cwd test test",
1111
"release": "standard-version",
1212
"--------------": "",
1313
"format": "prettier --write .",
14-
"clean": "npx -y rimraf -g dist **/*.tsbuildinfo ./test/projects/nx/dist",
15-
"clean:all": "yarn run clean && npx -y rimraf -g node_modules **/node_modules **/yarn.lock yarn.lock",
14+
"clean": "rimraf -g dist \"**/*.tsbuildinfo\" ./test/projects/nx/dist",
15+
"clean:all": "yarn run clean && rimraf -g node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock",
1616
"reset": "yarn run clean:all && yarn install && yarn build",
1717
"-------------- ": "",
18-
"prebuild": "npx -y rimraf -g dist",
19-
"install:tests": "cd test && yarn install",
20-
"prepare": "yarn run install:tests"
18+
"prepack": "yarn build",
19+
"pretest": "yarn --cwd test install",
20+
"prebuild": "rimraf -g dist"
2121
},
2222
"keywords": [
2323
"typescript",
@@ -55,15 +55,12 @@
5555
"nx-transformer.js"
5656
],
5757
"devDependencies": {
58-
"@types/jest": "^29.2.0",
5958
"@types/minimatch": "^5.1.2",
6059
"@types/node": "^18.11.2",
61-
"jest": "^29.7.0",
6260
"prettier": "^3.3.3",
6361
"rimraf": "^5.0.5",
6462
"standard-version": "^9.5.0",
6563
"@types/ts-expose-internals": "npm:[email protected]",
66-
"ts-jest": "^29.1.2",
6764
"ts-node": "^10.9.1",
6865
"ts-patch": "^3.1.2",
6966
"typescript": "^5.3.3"

test/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const tsModules = <const>[
2424
];
2525

2626
export const projectsPaths = path.join(__dirname, "./projects");
27-
export const transformerPath = path.resolve(__dirname, "../src/index.ts");
28-
export const builtTransformerPath = path.resolve(__dirname, "../dist/index.js");
27+
export const transformerPath = require.resolve("typescript-transform-paths");
28+
export const builtTransformerPath = require.resolve("typescript-transform-paths");
2929

3030
Error.stackTraceLimit = 120;
3131

jest.config.ts renamed to test/jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JestConfigWithTsJest } from "ts-jest/dist/types";
1+
import type { JestConfigWithTsJest } from "ts-jest";
22

33
const config: JestConfigWithTsJest = {
44
testEnvironment: "node",
@@ -9,7 +9,7 @@ const config: JestConfigWithTsJest = {
99
"^.+\\.tsx?$": [
1010
"ts-jest",
1111
{
12-
tsconfig: "<rootDir>/test/tsconfig.json",
12+
tsconfig: "<rootDir>/tsconfig.json",
1313
},
1414
],
1515
},

test/package.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
"private": true,
33
"license": "MIT",
44
"scripts": {
5+
"install-ttp": "yarn pack --cwd ../ --filename out.tgz && yarn add -W -D ./out.tgz",
6+
"test": "jest",
57
"prepare": "node prepare.js"
68
},
79
"devDependencies": {
8-
"typescript-transform-paths": "link:../src",
9-
"ts-expose-internals": "^4.1.2",
10-
"typescript-three": "npm:[email protected]",
11-
"typescript-four-seven": "npm:[email protected]",
12-
"ts-node": "link:../node_modues/ts-node",
13-
"typescript": "latest",
14-
"ts-patch": "latest",
15-
"tsp1": "npm:ts-patch@1.*.*",
16-
"tsp2": "npm:ts-patch@2.*.*",
1710
"@nrwl/cli": "^15.0.0",
1811
"@nrwl/js": "^15.0.0",
1912
"@nrwl/node": "^15.0.0",
2013
"@nrwl/workspace": "^15.0.0",
14+
"@types/jest": "^29.5.12",
15+
"jest": "^29.7.0",
2116
"nx": "^15.0.0",
22-
"strip-ansi": "^6.0.1"
17+
"strip-ansi": "^6.0.1",
18+
"ts-expose-internals": "^4.1.2",
19+
"ts-jest": "^29.2.4",
20+
"ts-node": "^10.9.2",
21+
"ts-patch": "latest",
22+
"tsp1": "npm:ts-patch@1.*.*",
23+
"tsp2": "npm:ts-patch@2.*.*",
24+
"typescript": "latest",
25+
"typescript-four-seven": "npm:[email protected]",
26+
"typescript-three": "npm:[email protected]",
27+
"typescript-transform-paths": "./out.tgz"
2328
},
2429
"workspaces": {
2530
"packages": [

test/projects/extras/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"private": true,
33
"name": "@tests/extras",
4-
"version": "0.0.0",
5-
"dependencies": {
6-
"typescript-transform-paths": "link:../../../"
7-
}
4+
"version": "0.0.0"
85
}

test/projects/general/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"esModuleInterop": true,
1818

1919
"plugins": [
20-
{ "transform": "../../../src/index.ts" },
21-
{ "transform": "../../../src/index.ts", "afterDeclarations": true }
20+
{ "transform": "typescript-transform-paths" },
21+
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
2222
]
2323
}
2424
}

test/projects/nx/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"name": "nx",
33
"version": "0.0.0",
44
"scripts": {
5-
"build": "npx nx build library1 --skip-nx-cache"
5+
"build": "nx build library1 --skip-nx-cache"
66
},
7-
"private": true,
8-
"dependencies": {},
9-
"devDependencies": {
10-
"typescript-transform-paths": "link:../../../"
11-
}
7+
"private": true
128
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"private": true,
33
"name": "@tests/project-ref",
4-
"version": "0.0.0",
5-
"dependencies": {
6-
"typescript-transform-paths": "link:../../../"
7-
}
4+
"version": "0.0.0"
85
}

test/projects/project-ref/tsconfig.base.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
},
1515
"plugins": [
1616
{
17-
"transform": "../../../../src/index.ts"
17+
"transform": "typescript-transform-paths"
1818
},
1919
{
20-
"transform": "../../../../src/index.ts",
20+
"transform": "typescript-transform-paths",
2121
"afterDeclarations": true
2222
}
2323
]

test/tests/extras.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ describe(`Extra Tests`, () => {
3636

3737
describe(`ts-node register script`, () => {
3838
test(`Works with --transpileOnly`, () => {
39-
const res = execSync("npx ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
39+
const res = execSync("yarn run --silent ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
4040
expect(stripAnsi(res)).toMatch(/^null($|\r?\n)/m);
4141
});
4242

4343
test(`Works with --typeCheck`, () => {
44-
const res = execSync("npx ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
44+
const res = execSync("yarn run --silent ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
4545
expect(stripAnsi(res)).toMatch(/^null($|\r?\n)/);
4646
});
4747
});

test/tests/nx.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import ts from "typescript";
2-
import { nxTransformerPlugin } from "../../src";
2+
import { nxTransformerPlugin } from "typescript-transform-paths";
33
import path from "path";
44
import { projectsPaths } from "../config";
55
import { execSync } from "child_process";
66
import { readFileSync, rmSync } from "fs";
7-
import * as transformerModule from "../../src/transformer";
7+
import * as transformerModule from "typescript-transform-paths/dist/transformer";
88

99
/* ****************************************************************************************************************** *
1010
* Tests

test/tests/register.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { register } from "../../src";
1+
import { register } from "typescript-transform-paths";
22
import { PluginConfig } from "ts-patch";
33
import * as tsNode from "ts-node";
4-
import * as transformerModule from "../../src/transformer";
4+
import * as transformerModule from "typescript-transform-paths/dist/transformer";
55
import { REGISTER_INSTANCE } from "ts-node";
66
import { CustomTransformers, PluginImport, Program } from "typescript";
77

test/tests/transformer/specific.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getTsNodeEmitResult,
1010
} from "../../utils";
1111
import { projectsPaths, ts, tsModules } from "../../config";
12-
import { TsTransformPathsConfig } from "../../../src";
12+
import { TsTransformPathsConfig } from "typescript-transform-paths";
1313
import TS from "typescript";
1414

1515
/* ****************************************************************************************************************** *

test/utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { default as tstpTransform, TsTransformPathsConfig } from "../../src";
1+
import { default as tstpTransform, TsTransformPathsConfig } from "typescript-transform-paths";
22
import fs from "fs";
33
import ts from "typescript";
44
import * as tsNode from "ts-node";

0 commit comments

Comments
 (0)