Skip to content

Commit

Permalink
Skip symlink tests and show warning message when tests are run withou…
Browse files Browse the repository at this point in the history
…t admin privilege. (parcel-bundler#2602)
  • Loading branch information
sainthkh committed Jan 31, 2019
1 parent 579915e commit b054ace
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 52 deletions.
34 changes: 21 additions & 13 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
ncp
} = require('./utils');
const {mkdirp} = require('@parcel/fs');
const {symlinkPrivilegeWarning} = require('@parcel/test-utils');
const {symlinkSync} = require('fs');

describe('javascript', function() {
Expand Down Expand Up @@ -1290,21 +1291,28 @@ describe('javascript', function() {
inputDir
);

// Create the symlink here to prevent cross platform and git issues
symlinkSync(
path.join(inputDir, 'packages/foo'),
path.join(inputDir, 'node_modules/foo'),
'dir'
);
try {
// Create the symlink here to prevent cross platform and git issues
symlinkSync(
path.join(inputDir, 'packages/foo'),
path.join(inputDir, 'node_modules/foo'),
'dir'
);

await bundle(inputDir + '/index.js');
await bundle(inputDir + '/index.js');

let file = await fs.readFile(
path.join(__dirname, '/dist/index.js'),
'utf8'
);
assert(file.includes('function Foo'));
assert(file.includes('function Bar'));
let file = await fs.readFile(
path.join(__dirname, '/dist/index.js'),
'utf8'
);
assert(file.includes('function Foo'));
assert(file.includes('function Bar'));
} catch(e) {
if(e.perm == 'EPERM') {
symlinkPrivilegeWarning();
this.skip();
}
}
});

it('should not compile node_modules with a source field in package.json when not symlinked', async function() {
Expand Down
56 changes: 32 additions & 24 deletions packages/core/integration-tests/test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
ncp
} = require('./utils');
const {sleep} = require('@parcel/test-utils');
const {symlinkPrivilegeWarning} = require('@parcel/test-utils');
const {symlinkSync} = require('fs');

const inputDir = path.join(__dirname, '/input');
Expand Down Expand Up @@ -274,29 +275,36 @@ describe('watcher', function() {
inputDir
);

// Create the symlink here to prevent cross platform and git issues
symlinkSync(
path.join(inputDir, 'local.js'),
path.join(inputDir, 'src/symlinked_local.js')
);

b = bundler(path.join(inputDir, '/src/index.js'), {
watch: true
});

let bundle = await b.bundle();
let output = await run(bundle);

assert.equal(output(), 3);

await sleep(100);
fs.writeFile(
path.join(inputDir, '/local.js'),
'exports.a = 5; exports.b = 5;'
);

bundle = await nextBundle(b);
output = await run(bundle);
assert.equal(output(), 10);
try {
// Create the symlink here to prevent cross platform and git issues
symlinkSync(
path.join(inputDir, 'local.js'),
path.join(inputDir, 'src/symlinked_local.js')
);

b = bundler(path.join(inputDir, '/src/index.js'), {
watch: true
});

let bundle = await b.bundle();
let output = await run(bundle);

assert.equal(output(), 3);

await sleep(100);
fs.writeFile(
path.join(inputDir, '/local.js'),
'exports.a = 5; exports.b = 5;'
);

bundle = await nextBundle(b);
output = await run(bundle);
assert.equal(output(), 10);
} catch(e) {
if(e.code == 'EPERM') {
symlinkPrivilegeWarning();
this.skip();
}
}
});
});
48 changes: 33 additions & 15 deletions packages/core/parcel-bundler/test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,43 @@ const path = require('path');
const assert = require('assert');
const {rimraf, ncp} = require('./utils');
const {mkdirp} = require('@parcel/fs');
const {symlinkPrivilegeWarning} = require('@parcel/test-utils');
const {symlinkSync} = require('fs');

const rootDir = path.join(__dirname, 'input/resolver');

describe('resolver', function() {
let resolver;
let hasPrivilege = true;

before(async function() {
await rimraf(path.join(__dirname, '/input'));
await mkdirp(rootDir);
await ncp(path.join(__dirname, 'integration/resolver'), rootDir);

// Create the symlinks here to prevent cross platform and git issues
symlinkSync(
path.join(rootDir, 'packages/source'),
path.join(rootDir, 'node_modules/source'),
'dir'
);
symlinkSync(
path.join(rootDir, 'packages/source-alias'),
path.join(rootDir, 'node_modules/source-alias'),
'dir'
);
symlinkSync(
path.join(rootDir, 'packages/source-alias-glob'),
path.join(rootDir, 'node_modules/source-alias-glob'),
'dir'
);
try {
symlinkSync(
path.join(rootDir, 'packages/source'),
path.join(rootDir, 'node_modules/source'),
'dir'
);
symlinkSync(
path.join(rootDir, 'packages/source-alias'),
path.join(rootDir, 'node_modules/source-alias'),
'dir'
);
symlinkSync(
path.join(rootDir, 'packages/source-alias-glob'),
path.join(rootDir, 'node_modules/source-alias-glob'),
'dir'
);
} catch (e) {
if (e.code == 'EPERM') {
symlinkPrivilegeWarning();
hasPrivilege = false;
}
}

resolver = new Resolver({
rootDir,
Expand Down Expand Up @@ -579,6 +589,8 @@ describe('resolver', function() {

describe('source field', function() {
it('should use the source field when symlinked', async function() {
if (!hasPrivilege) this.skip();

let resolved = await resolver.resolve(
'source',
path.join(rootDir, 'foo.js')
Expand All @@ -591,6 +603,8 @@ describe('resolver', function() {
});

it('should not use the source field when not symlinked', async function() {
if (!hasPrivilege) this.skip();

let resolved = await resolver.resolve(
'source-not-symlinked',
path.join(rootDir, 'foo.js')
Expand All @@ -603,6 +617,8 @@ describe('resolver', function() {
});

it('should use the source field as an alias when symlinked', async function() {
if (!hasPrivilege) this.skip();

let resolved = await resolver.resolve(
'source-alias/dist',
path.join(rootDir, 'foo.js')
Expand All @@ -615,6 +631,8 @@ describe('resolver', function() {
});

it('should use the source field as a glob alias when symlinked', async function() {
if (!hasPrivilege) this.skip();

let resolved = await resolver.resolve(
'source-alias-glob',
path.join(rootDir, 'foo.js')
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

function symlinkPrivilegeWarning() {
console.error("-----------------------------------")
console.error("Skipping symbolic link test(s) because you don't have the privilege.");
console.error("Run tests with Administrator privilege.");
console.error("If you don't know how, check here: https://bit.ly/2UmWsbD");
console.error("-----------------------------------")
}

exports.sleep = sleep;
exports.symlinkPrivilegeWarning = symlinkPrivilegeWarning;

0 comments on commit b054ace

Please sign in to comment.