Skip to content

Commit

Permalink
update extras
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Aug 19, 2024
1 parent cf296bb commit c4ce5c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
18 changes: 4 additions & 14 deletions test/projects/extras/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
{
// "extends": "@tsconfig/node18",
"include": ["src"],

"ts-node": {
"require": ["typescript-transform-paths/register"]
},

"compilerOptions": {
"target": "esnext",
"noEmit": true,
"outDir": "dist",

"rootDir": ".",
"module": "CommonJS",
"esModuleInterop": true,
"moduleResolution": "node",
"declaration": true,

"baseUrl": "./src",
"paths": {
"#identifier": ["./id.ts"]
},

"plugins": [
{
"transform": "typescript-transform-paths"
},
{
"transform": "typescript-transform-paths",
"afterDeclarations": true
}
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}
38 changes: 25 additions & 13 deletions test/tests/extras.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils";
import { createTsProgram, getEmitResultFromProgram, getRelativeEmittedFiles, ModuleNotFoundError } from "../utils";
import { projectsPaths } from "../config";
import path from "node:path";
import ts from "typescript";
Expand All @@ -7,7 +7,6 @@ import { execSync } from "node:child_process";

describe(`Extra Tests`, () => {
const projectRoot = ts.normalizePath(path.join(projectsPaths, "extras"));
const indexFile = ts.normalizePath(path.join(projectRoot, "src/index.ts"));
const tsConfigFile = ts.normalizePath(path.join(projectRoot, "tsconfig.json"));

describe(`Built Tests`, () => {
Expand All @@ -19,27 +18,40 @@ describe(`Extra Tests`, () => {
try {
const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath);
const res = getEmitResultFromProgram(program);
expect(res[indexFile].js).toMatch(`var _identifier_1 = require("./id")`);
expect(getRelativeEmittedFiles(projectRoot, res)).toMatchInlineSnapshot(`
{
"src/id.ts": {
"dts": "export declare const b: any;
",
"js": "export const b = null;
",
},
"src/index.ts": {
"dts": "export * from "./id";
",
"js": "export * from "./id";
import { b } from "./id";
console.log(b);
",
},
}
`);
} finally {
jest.dontMock("ts-node");
}
});

describe(`ts-node register script`, () => {
test(`Works with --transpileOnly`, () => {
const res = execSync("yarn g:ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString();
expect(res).toMatchInlineSnapshot(`
"null
"
`);
expect(
execSync("yarn g:ts-node --transpileOnly src/index.ts", { cwd: projectRoot }).toString().trim(),
).toMatchInlineSnapshot(`"null"`);
});

test(`Works with --typeCheck`, () => {
const res = execSync("yarn g:ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString();
expect(res).toMatchInlineSnapshot(`
"null
"
`);
expect(
execSync("yarn g:ts-node --typeCheck src/index.ts", { cwd: projectRoot }).toString().trim(),
).toMatchInlineSnapshot(`"null"`);
});
});
});
Expand Down

0 comments on commit c4ce5c7

Please sign in to comment.