Skip to content

refact: use yarn pack to generate package for testing #216

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

Merged
merged 20 commits into from
Aug 7, 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
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ jobs:
cache: yarn
cache-dependency-path: "**/yarn.lock"

- run: yarn install --frozen-lockfile
- run: yarn install

- run: yarn build

- name: Install dependencies for testing
run: |
yarn install-ttp
yarn install
working-directory: test

- name: Test
working-directory: test
run: yarn test --runInBand=false --maxWorkers=2 --workerIdleMemoryLimit=2GB # https://github.com/facebook/jest/issues/11956
env:
NODE_OPTIONS: --max_old_space_size=4096
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ fabric.properties

# Editor-based Rest Client
.idea/httpRequests

test/out.tgz
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"scripts": {
"compile": "tsc",
"build": "yarn run clean && yarn run compile",
"test": "jest",
"test": "yarn --cwd test test",
"release": "standard-version",
"--------------": "",
"format": "prettier --write .",
"clean": "npx -y rimraf -g dist **/*.tsbuildinfo ./test/projects/nx/dist",
"clean:all": "yarn run clean && npx -y rimraf -g node_modules **/node_modules **/yarn.lock yarn.lock",
"clean": "rimraf -g dist \"**/*.tsbuildinfo\" ./test/projects/nx/dist",
"clean:all": "yarn run clean && rimraf -g node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock",
"reset": "yarn run clean:all && yarn install && yarn build",
"-------------- ": "",
"prebuild": "npx -y rimraf -g dist",
"install:tests": "cd test && yarn install",
"prepare": "yarn run install:tests"
"prepack": "yarn build",
"pretest": "yarn --cwd test install",
"prebuild": "rimraf -g dist"
},
"keywords": [
"typescript",
Expand Down Expand Up @@ -55,15 +55,12 @@
"nx-transformer.js"
],
"devDependencies": {
"@types/jest": "^29.2.0",
"@types/minimatch": "^5.1.2",
"@types/node": "^18.11.2",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"rimraf": "^5.0.5",
"standard-version": "^9.5.0",
"@types/ts-expose-internals": "npm:[email protected]",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.1",
"ts-patch": "^3.1.2",
"typescript": "^5.3.3"
Expand Down
4 changes: 2 additions & 2 deletions test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const tsModules = <const>[
];

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

Error.stackTraceLimit = 120;

Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts → test/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JestConfigWithTsJest } from "ts-jest/dist/types";
import type { JestConfigWithTsJest } from "ts-jest";

const config: JestConfigWithTsJest = {
testEnvironment: "node",
Expand All @@ -9,7 +9,7 @@ const config: JestConfigWithTsJest = {
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: "<rootDir>/test/tsconfig.json",
tsconfig: "<rootDir>/tsconfig.json",
},
],
},
Expand Down
25 changes: 15 additions & 10 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
"private": true,
"license": "MIT",
"scripts": {
"install-ttp": "yarn pack --cwd ../ --filename out.tgz && yarn add -W -D ./out.tgz",
"test": "jest",
"prepare": "node prepare.js"
},
"devDependencies": {
"typescript-transform-paths": "link:../src",
"ts-expose-internals": "^4.1.2",
"typescript-three": "npm:[email protected]",
"typescript-four-seven": "npm:[email protected]",
"ts-node": "link:../node_modues/ts-node",
"typescript": "latest",
"ts-patch": "latest",
"tsp1": "npm:ts-patch@1.*.*",
"tsp2": "npm:ts-patch@2.*.*",
"@nrwl/cli": "^15.0.0",
"@nrwl/js": "^15.0.0",
"@nrwl/node": "^15.0.0",
"@nrwl/workspace": "^15.0.0",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"nx": "^15.0.0",
"strip-ansi": "^6.0.1"
"strip-ansi": "^6.0.1",
"ts-expose-internals": "^4.1.2",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"ts-patch": "latest",
"tsp1": "npm:ts-patch@1.*.*",
"tsp2": "npm:ts-patch@2.*.*",
"typescript": "latest",
"typescript-four-seven": "npm:[email protected]",
"typescript-three": "npm:[email protected]",
"typescript-transform-paths": "./out.tgz"
},
"workspaces": {
"packages": [
Expand Down
5 changes: 1 addition & 4 deletions test/projects/extras/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"private": true,
"name": "@tests/extras",
"version": "0.0.0",
"dependencies": {
"typescript-transform-paths": "link:../../../"
}
"version": "0.0.0"
}
4 changes: 2 additions & 2 deletions test/projects/general/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"esModuleInterop": true,

"plugins": [
{ "transform": "../../../src/index.ts" },
{ "transform": "../../../src/index.ts", "afterDeclarations": true }
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}
8 changes: 2 additions & 6 deletions test/projects/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"name": "nx",
"version": "0.0.0",
"scripts": {
"build": "npx nx build library1 --skip-nx-cache"
"build": "nx build library1 --skip-nx-cache"
},
"private": true,
"dependencies": {},
"devDependencies": {
"typescript-transform-paths": "link:../../../"
}
"private": true
}
5 changes: 1 addition & 4 deletions test/projects/project-ref/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"private": true,
"name": "@tests/project-ref",
"version": "0.0.0",
"dependencies": {
"typescript-transform-paths": "link:../../../"
}
"version": "0.0.0"
}
4 changes: 2 additions & 2 deletions test/projects/project-ref/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
},
"plugins": [
{
"transform": "../../../../src/index.ts"
"transform": "typescript-transform-paths"
},
{
"transform": "../../../../src/index.ts",
"transform": "typescript-transform-paths",
"afterDeclarations": true
}
]
Expand Down
4 changes: 2 additions & 2 deletions test/tests/extras.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ describe(`Extra Tests`, () => {

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

test(`Works with --typeCheck`, () => {
const res = execSync("npx ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
const res = execSync("yarn run --silent ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
expect(stripAnsi(res)).toMatch(/^null($|\r?\n)/);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/tests/nx.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ts from "typescript";
import { nxTransformerPlugin } from "../../src";
import { nxTransformerPlugin } from "typescript-transform-paths";
import path from "path";
import { projectsPaths } from "../config";
import { execSync } from "child_process";
import { readFileSync, rmSync } from "fs";
import * as transformerModule from "../../src/transformer";
import * as transformerModule from "typescript-transform-paths/dist/transformer";

/* ****************************************************************************************************************** *
* Tests
Expand Down
4 changes: 2 additions & 2 deletions test/tests/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { register } from "../../src";
import { register } from "typescript-transform-paths";
import { PluginConfig } from "ts-patch";
import * as tsNode from "ts-node";
import * as transformerModule from "../../src/transformer";
import * as transformerModule from "typescript-transform-paths/dist/transformer";
import { REGISTER_INSTANCE } from "ts-node";
import { CustomTransformers, PluginImport, Program } from "typescript";

Expand Down
2 changes: 1 addition & 1 deletion test/tests/transformer/specific.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getTsNodeEmitResult,
} from "../../utils";
import { projectsPaths, ts, tsModules } from "../../config";
import { TsTransformPathsConfig } from "../../../src";
import { TsTransformPathsConfig } from "typescript-transform-paths";
import TS from "typescript";

/* ****************************************************************************************************************** *
Expand Down
2 changes: 1 addition & 1 deletion test/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as tstpTransform, TsTransformPathsConfig } from "../../src";
import { default as tstpTransform, TsTransformPathsConfig } from "typescript-transform-paths";
import fs from "fs";
import ts from "typescript";
import * as tsNode from "ts-node";
Expand Down
Loading