Skip to content

Commit 033d4dc

Browse files
rnkdevsindresorhus
authored andcommitted
Support symlinked test files - fixes #1143 (#1145)
1 parent 415cd2f commit 033d4dc

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var EventEmitter = require('events').EventEmitter;
33
var path = require('path');
44
var util = require('util');
5+
var fs = require('fs');
56
var commonPathPrefix = require('common-path-prefix');
67
var uniqueTempDir = require('unique-temp-dir');
78
var findCacheDir = require('find-cache-dir');
@@ -67,7 +68,8 @@ module.exports = Api;
6768
Api.prototype._runFile = function (file, runStatus, execArgv) {
6869
var hash = this.precompiler.precompileFile(file);
6970
var precompiled = {};
70-
precompiled[file] = hash;
71+
var resolvedfpath = fs.realpathSync(file);
72+
precompiled[resolvedfpath] = hash;
7173

7274
var options = objectAssign({}, this.options, {
7375
precompiled: precompiled

test/api.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,28 @@ function generateTests(prefix, apiCreator) {
491491
});
492492
});
493493

494+
test(prefix + 'symlink to directory containing test files', function (t) {
495+
t.plan(1);
496+
497+
var api = apiCreator();
498+
499+
return api.run([path.join(__dirname, 'fixture/symlink')])
500+
.then(function (result) {
501+
t.is(result.passCount, 1);
502+
});
503+
});
504+
505+
test(prefix + 'symlink to test file directly', function (t) {
506+
t.plan(1);
507+
508+
var api = apiCreator();
509+
510+
return api.run([path.join(__dirname, 'fixture/symlinkfile.js')])
511+
.then(function (result) {
512+
t.is(result.passCount, 1);
513+
});
514+
});
515+
494516
test(prefix + 'search directories recursively for files', function (t) {
495517
t.plan(2);
496518

test/fixture/symlink

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./symlinkdir

test/fixture/symlinkdir/symlink.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../';
2+
3+
test(t => {
4+
t.pass();
5+
});

test/fixture/symlinkfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./target-symlink.js

test/fixture/target-symlink.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../';
2+
3+
test(t => {
4+
t.pass();
5+
});

0 commit comments

Comments
 (0)