diff --git a/packages/core/integration-tests/test/javascript.js b/packages/core/integration-tests/test/javascript.js index ba255be5792..f3271074a84 100644 --- a/packages/core/integration-tests/test/javascript.js +++ b/packages/core/integration-tests/test/javascript.js @@ -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() { @@ -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() { diff --git a/packages/core/integration-tests/test/kotlin.js b/packages/core/integration-tests/test/kotlin.js index 0e62f88133d..c4b76598bd9 100644 --- a/packages/core/integration-tests/test/kotlin.js +++ b/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'); diff --git a/packages/core/integration-tests/test/watcher.js b/packages/core/integration-tests/test/watcher.js index 58bee8fb362..723e95bbdb1 100644 --- a/packages/core/integration-tests/test/watcher.js +++ b/packages/core/integration-tests/test/watcher.js @@ -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'); @@ -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(); + } + } }); }); diff --git a/packages/core/parcel-bundler/test/resolver.js b/packages/core/parcel-bundler/test/resolver.js index f16bdd7d9cd..3812d3659fb 100644 --- a/packages/core/parcel-bundler/test/resolver.js +++ b/packages/core/parcel-bundler/test/resolver.js @@ -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, @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/packages/core/test-utils/src/utils.js b/packages/core/test-utils/src/utils.js index 4cdf552655a..65cfdf23b7c 100644 --- a/packages/core/test-utils/src/utils.js +++ b/packages/core/test-utils/src/utils.js @@ -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; \ No newline at end of file