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

Fixing some tests that fail because of environment setups. #2590

Closed
wants to merge 4 commits into from
Closed
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
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
8 changes: 8 additions & 0 deletions packages/core/integration-tests/test/kotlin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const assert = require('assert');
const {bundle, assertBundleTree, run} = require('./utils');
const commandExists = require('command-exists')

describe('kotlin', function() {
if (!commandExists.sync('java')) {
console.log(
'Skipping Kotlin tests. Install https://www.java.com/download/ to run them.'
);
return;
}

it('should produce a basic kotlin bundle', async function() {
let b = await bundle(__dirname + '/integration/kotlin/index.js');

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;