Skip to content
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

Fix path sep and run all unit tests against root #156

Merged
merged 6 commits into from
Sep 4, 2020
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
2 changes: 1 addition & 1 deletion src/node-file-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class Job {
// keep backtracking for realpath, emitting folder symlinks within base
if (!inPath(path, this.base))
return path;
return this.realpath(dirname(path), parent, seen) + sep + basename(path);
return join(this.realpath(dirname(path), parent, seen), basename(path));
}

emitFile (path: string, reason: string, parent?: string, isRealpath = false) {
Expand Down
36 changes: 20 additions & 16 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ const { nodeFileTrace } = require('../out/node-file-trace');
global._unit = true;

const skipOnWindows = ['yarn-workspaces', 'yarn-workspaces-base-root', 'yarn-workspace-esm', 'asset-symlink', 'require-symlink'];
const setBaseToRoot = ['yarn-workspaces-base-root'];
const unitTestDirs = fs.readdirSync(join(__dirname, 'unit'));
const unitTests = [
...unitTestDirs.map(testName => ({testName, isRoot: false})),
...unitTestDirs.map(testName => ({testName, isRoot: true})),
];

for (const unitTest of fs.readdirSync(join(__dirname, 'unit'))) {
if (process.platform === 'win32' && skipOnWindows.includes(unitTest)) {
console.log('skipping symlink test on Windows: ' + unitTest);
for (const { testName, isRoot } of unitTests) {
const testSuffix = `${testName} from ${isRoot ? 'root' : 'cwd'}`;
if (process.platform === 'win32' && (isRoot || skipOnWindows.includes(testName))) {
console.log(`Skipping unit test on Windows: ${testSuffix}`);
continue;
}
it(`should correctly trace ${unitTest}`, async () => {
const unitPath = join(__dirname, 'unit', unitTest);
};
it(`should correctly trace ${testSuffix}`, async () => {
const unitPath = join(__dirname, 'unit', testName);

// We mock readFile because when node-file-trace is integrated into @now/node
// this is the hook that triggers TypeScript compilation. So if this doesn't
Expand All @@ -25,26 +30,25 @@ for (const unitTest of fs.readdirSync(join(__dirname, 'unit'))) {

let inputFileName = "input.js";

if (unitTest === "tsx-input") {
if (testName === "tsx-input") {
inputFileName = "input.tsx";
}

const isRoot = setBaseToRoot.includes(unitTest);

const { fileList, reasons } = await nodeFileTrace([join(unitPath, inputFileName)], {
base: isRoot ? '/' : `${__dirname}/../`,
processCwd: unitPath,
paths: {
dep: 'test/unit/esm-paths/esm-dep.js',
'dep/': 'test/unit/esm-paths-trailer/'
dep: `${__dirname}/../test/unit/esm-paths/esm-dep.js`,
'dep/': `${__dirname}/../test/unit/esm-paths-trailer/`
},
exportsOnly: unitTest.startsWith('exports-only'),
exportsOnly: testName.startsWith('exports-only'),
ts: true,
log: true,
// disable analysis for basic-analysis unit tests
analysis: !unitTest.startsWith('basic-analysis'),
analysis: !testName.startsWith('basic-analysis'),
mixedModules: true,
ignore: '**/actual.js',
// Ignore unit test output "actual.js", and ignore GitHub Actions preinstalled packages
ignore: (str) => str.endsWith('/actual.js') || str.startsWith('usr/local'),
readFile: readFileMock
});
let expected;
Expand Down Expand Up @@ -73,7 +77,7 @@ for (const unitTest of fs.readdirSync(join(__dirname, 'unit'))) {
throw e;
}

if (unitTest === "tsx-input") {
if (testName === "tsx-input") {
expect(readFileMock.mock.calls.length).toBe(2);
}
});
Expand Down
2 changes: 0 additions & 2 deletions test/unit/yarn-workspaces-base-root/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion test/unit/yarn-workspaces-base-root/input.js

This file was deleted.

1 change: 0 additions & 1 deletion test/unit/yarn-workspaces-base-root/node_modules/x

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/yarn-workspaces-base-root/output.js

This file was deleted.

1 change: 0 additions & 1 deletion test/unit/yarn-workspaces-base-root/packages/x/dep.js

This file was deleted.

1 change: 0 additions & 1 deletion test/unit/yarn-workspaces-base-root/packages/x/main.ts

This file was deleted.

3 changes: 0 additions & 3 deletions test/unit/yarn-workspaces-base-root/packages/x/package.json

This file was deleted.