Skip to content

Commit

Permalink
test: add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pkerschbaum committed Sep 15, 2024
1 parent 2294bc7 commit 970bbbe
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 1,961 deletions.
1,955 changes: 0 additions & 1,955 deletions blah.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.png' {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ import { constant } from '#pkg/some-directory';

import { constant as constant2 } from './some-directory';
import { constant as constant3 } from './some-directory/index';

import './test.png';

import { someConstant } from './lib/some-js';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const someConstant: string;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.someConstant = '';
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
},
"types": ["node"]
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"exclude": ["src/lib/**"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import defaultExport from '#pkg/some-module';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function noop() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
/* Language and Environment */
"target": "ES2018",

/* Modules */
"baseUrl": "./src",
"module": "commonjs",
"paths": {
"#pkg/*": ["./*"]
},
"types": ["node"]
},
"include": ["src/**/*"],
"exclude": ["src/lib/**"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.png' {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ import { constant } from '#pkg/some-directory/index.js';

import { constant as constant2 } from './some-directory/index.js';
import { constant as constant3 } from './some-directory/index.js';

import './test.png';

import { someConstant } from './lib/some-js.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import defaultExport from '#pkg/some-module.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function noop() {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import { loadTypeScriptProgram } from '#pkg/load-typescript-program.js';
import { rewriteModuleSpecifiersOfTypeScriptProject } from '#pkg/transform/index.js';

const PATH_TO_TRANSFORMER_INPUTS = path.join(__dirname, 'transformer-inputs');
const PROJECTS = {
PROJECT_1_DIRECTORY: path.join(PATH_TO_TRANSFORMER_INPUTS, 'project-1'),
};

test('fixture-1', async () => {
const projectAbsolutePath = path.join(PROJECTS.PROJECT_1_DIRECTORY, 'tsconfig.json');
test('project-1', async () => {
const projectAbsolutePath = path.join(PATH_TO_TRANSFORMER_INPUTS, 'project-1', 'tsconfig.json');
const basepath = path.dirname(projectAbsolutePath);

const typeScriptProgram = await loadTypeScriptProgram({ project: projectAbsolutePath, basepath });
Expand All @@ -31,3 +28,25 @@ test('fixture-1', async () => {
}),
);
});

test('project-2', async () => {
const projectAbsolutePath = path.join(PATH_TO_TRANSFORMER_INPUTS, 'project-2', 'tsconfig.json');
const basepath = path.dirname(projectAbsolutePath);

const typeScriptProgram = await loadTypeScriptProgram({ project: projectAbsolutePath, basepath });

await Promise.all(
typeScriptProgram.fileNames.map(async (absolutePathSourceFile) => {
const text = await fs.promises.readFile(absolutePathSourceFile, 'utf8');
const newText = rewriteModuleSpecifiersOfTypeScriptProject(
typeScriptProgram,
absolutePathSourceFile,
text,
);
const relativePathFromRootDir = path.relative(basepath, absolutePathSourceFile);
await expect(newText).toMatchFileSnapshot(
`./transformer-outputs/project-2/${relativePathFromRootDir}`,
);
}),
);
});

0 comments on commit 970bbbe

Please sign in to comment.