Skip to content

Commit

Permalink
Do symlinks at test time
Browse files Browse the repository at this point in the history
  • Loading branch information
Giancarlo Anemone committed Mar 31, 2020
1 parent 71d43df commit 36c1264
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/examples/*/node_modules/
/examples/mongodb/globalConfig.json

/e2e/preserve-symlinks/*
/e2e/*/node_modules
/e2e/*/.pnp
/e2e/*/.pnp.js
Expand Down
65 changes: 56 additions & 9 deletions e2e/__tests__/preserveSymlinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,55 @@
* LICENSE file in the root directory of this source tree.
*/

import {resolve} from 'path';
import {existsSync, mkdirSync, rmdirSync, symlinkSync, unlinkSync} from 'fs';
import {join, resolve} from 'path';

import {wrap} from 'jest-snapshot-serializer-raw';
import runJest from '../runJest';
import {extractSummary} from '../Utils';
import HasteMap = require('jest-haste-map');

const destRoot = resolve(__dirname, '../preserve-symlinks');
const srcRoot = resolve(__dirname, '../symlinked-source-dir');

const files = [
'package.json',
'a.js',
'b.js',
'ab.js',
'__tests__/a.test.js',
'__tests__/b.test.js',
'__tests__/ab.test.js',
];

function cleanup() {
files
.map(f => join(destRoot, f))
.filter(f => existsSync(f))
.forEach(f => {
unlinkSync(f);
});
if (existsSync(join(destRoot, '__tests__'))) {
rmdirSync(join(destRoot, '__tests__'));
}
if (existsSync(destRoot)) {
rmdirSync(destRoot);
}
}

beforeAll(() => {
cleanup();
mkdirSync(destRoot);
mkdirSync(join(destRoot, '__tests__'));
files.forEach(f => {
symlinkSync(join(srcRoot, f), join(destRoot, f));
});
});

afterAll(() => {
cleanup();
});

test('preserving symlinks', () => {
const {stderr, exitCode} = runJest('preserve-symlinks', ['--no-watchman'], {
preserveSymlinks: '1',
Expand Down Expand Up @@ -48,15 +91,19 @@ test('hasteMap finds symlinks correctly', async () => {
};
const hasteMap = new HasteMap(options);
const result = await hasteMap.build();
console.log('FILES', result.hasteFS.getAllFiles());
expect(result.hasteFS.getAllFiles()).toMatchInlineSnapshot(`
expect(
result.hasteFS
.getAllFiles()
.map(f => f.split('preserve-symlinks').pop())
.sort(),
).toMatchInlineSnapshot(`
Array [
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/a.js",
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/ab.js",
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/b.js",
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/b.test.js",
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/a.test.js",
"/Users/giancarloanemone/dev/jest/e2e/preserve-symlinks/__tests__/ab.test.js",
"/__tests__/a.test.js",
"/__tests__/ab.test.js",
"/__tests__/b.test.js",
"/a.js",
"/ab.js",
"/b.js",
]
`);
});
1 change: 0 additions & 1 deletion e2e/preserve-symlinks/__tests__/a.test.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/__tests__/ab.test.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/__tests__/b.test.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/a.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/ab.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/b.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/preserve-symlinks/package.json

This file was deleted.

7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/__tests__/a.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const a = require('../a');

test('a', () => {
Expand Down
7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/__tests__/ab.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const ab = require('../ab');

test('ab', () => {
Expand Down
7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/__tests__/b.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const b = require('../b');

test('b', () => {
Expand Down
7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/a.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = function a() {
return 'a';
};
7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/ab.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const a = require('./a');
const b = require('./b');

Expand Down
7 changes: 7 additions & 0 deletions e2e/symlinked-source-dir/b.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
module.exports = function b() {
return 'b';
};

0 comments on commit 36c1264

Please sign in to comment.