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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 21 additions & 13 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -10,6 +10,7 @@ const {
ncp
} = require('./utils');
const {mkdirp} = require('@parcel/fs');
const {symlinkPrivilegeWarning} = require('@parcel/utils').errorUtils;
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
@@ -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
Expand Up @@ -11,6 +11,7 @@ const {
ncp
} = require('./utils');
const {sleep} = require('@parcel/test-utils');
const {symlinkPrivilegeWarning} = require('@parcel/utils').errorUtils;
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
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/utils').errorUtils;
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/utils/src/errorUtils.js
Expand Up @@ -27,5 +27,14 @@ function jsonToError(json) {
}
}

function symlinkPrivilegeWarning() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be part of utils.
We should probably make a utils package for testing Parcel and Parcel plugins somewhere in the future to prevent installing test specific utils to every users download of Parcel.

For now this is good enough though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you know, parcel-bundler/test/utils.js and integration-tests/test/utils.js are exactly same. Because of that, I wondered what to do.

Now I found the test-util package. How about moving this to that package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea, didn't know there was a test-utils package already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question:

How about merging parcel-bundler/test/utils.js and integration-tests/test/utils.js to test-utils/utils.js this time?

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.errorToJson = errorToJson;
exports.jsonToError = jsonToError;
exports.symlinkPrivilegeWarning = symlinkPrivilegeWarning;