diff --git a/appveyor.yml b/appveyor.yml index 49dc22b02b7..5eb7846d386 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,6 @@ environment: matrix: - nodejs_version: "6" - nodejs_version: "8" - - nodejs_version: "10" # Install scripts. (runs after repo cloning) install: @@ -20,11 +19,6 @@ install: - rustc -Vv - cargo -V - # Restore symlinks from git - # https://github.com/appveyor/ci/issues/650 - - cmd: git config core.symlinks true - - cmd: git reset --hard - # Post-install test scripts. test_script: # Output useful info for debugging. diff --git a/src/Bundler.js b/src/Bundler.js index 87057e0d577..9f8da4be1c8 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -19,7 +19,7 @@ const installPackage = require('./utils/installPackage'); const bundleReport = require('./utils/bundleReport'); const prettifyTime = require('./utils/prettifyTime'); const getRootDir = require('./utils/getRootDir'); -const glob = require('fast-glob'); +const {glob} = require('./utils/glob'); /** * The Bundler is the main entry point. It resolves and loads assets, diff --git a/src/FSCache.js b/src/FSCache.js index fee757bfcec..a1ddd1aedce 100644 --- a/src/FSCache.js +++ b/src/FSCache.js @@ -4,8 +4,7 @@ const md5 = require('./utils/md5'); const objectHash = require('./utils/objectHash'); const pkg = require('../package.json'); const logger = require('./Logger'); -const glob = require('fast-glob'); -const isGlob = require('is-glob'); +const {isGlob, glob} = require('./utils/glob'); // These keys can affect the output, so if they differ, the cache should not match const OPTION_KEYS = ['publicURL', 'minify', 'hmr', 'target', 'scopeHoist']; diff --git a/src/Parser.js b/src/Parser.js index ca7072da8f3..18521e97689 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -1,7 +1,7 @@ const path = require('path'); const RawAsset = require('./assets/RawAsset'); const GlobAsset = require('./assets/GlobAsset'); -const isGlob = require('is-glob'); +const {isGlob} = require('./utils/glob'); class Parser { constructor(options = {}) { diff --git a/src/Resolver.js b/src/Resolver.js index 4cedb233e7a..d6de2c32bbe 100755 --- a/src/Resolver.js +++ b/src/Resolver.js @@ -1,7 +1,7 @@ const builtins = require('./builtins'); const nodeBuiltins = require('node-libs-browser'); const path = require('path'); -const isGlob = require('is-glob'); +const {isGlob} = require('./utils/glob'); const fs = require('./utils/fs'); const micromatch = require('micromatch'); @@ -147,7 +147,7 @@ class Resolver { default: // Module - return path.normalize(filename); + return filename; } } diff --git a/src/assets/GlobAsset.js b/src/assets/GlobAsset.js index af7451f7ac2..e9d6eb594c5 100644 --- a/src/assets/GlobAsset.js +++ b/src/assets/GlobAsset.js @@ -1,7 +1,7 @@ const Asset = require('../Asset'); -const glob = require('fast-glob'); const micromatch = require('micromatch'); const path = require('path'); +const {glob} = require('../utils/glob'); class GlobAsset extends Asset { constructor(name, options) { diff --git a/src/assets/StylusAsset.js b/src/assets/StylusAsset.js index 1eff9568447..114fc0e293f 100644 --- a/src/assets/StylusAsset.js +++ b/src/assets/StylusAsset.js @@ -4,8 +4,7 @@ const localRequire = require('../utils/localRequire'); const Resolver = require('../Resolver'); const fs = require('../utils/fs'); const {dirname, resolve, relative} = require('path'); -const isGlob = require('is-glob'); -const glob = require('fast-glob'); +const {isGlob, glob} = require('../utils/glob'); const URL_RE = /^(?:url\s*\(\s*)?['"]?(?:[#/]|(?:https?:)?\/\/)/i; diff --git a/src/utils/glob.js b/src/utils/glob.js new file mode 100644 index 00000000000..0c19bb26263 --- /dev/null +++ b/src/utils/glob.js @@ -0,0 +1,18 @@ +const isGlob = require('is-glob'); +const fastGlob = require('fast-glob'); + +function normalisePath(p) { + return p.replace(/\\/g, '/'); +} + +exports.isGlob = function(p) { + return isGlob(normalisePath(p)); +}; + +exports.glob = function(p, options) { + return fastGlob(normalisePath(p), options); +}; + +exports.glob.sync = function(p, options) { + return fastGlob.sync(normalisePath(p), options); +}; diff --git a/test/asset.js b/test/asset.js index b2981983243..5992bf3b740 100644 --- a/test/asset.js +++ b/test/asset.js @@ -24,7 +24,7 @@ describe('Asset', () => { it('should support overriding the filename of the root bundle', async function() { const outFile = 'custom-out-file.html'; - await bundle(__dirname + '/integration/html/index.html', { + await bundle(path.join(__dirname, '/integration/html/index.html'), { outFile }); diff --git a/test/autoinstall.js b/test/autoinstall.js index af60551db03..86cb8e90a54 100644 --- a/test/autoinstall.js +++ b/test/autoinstall.js @@ -2,13 +2,14 @@ const assert = require('assert'); const install = require('../src/utils/installPackage'); const fs = require('../src/utils/fs'); const {ncp, rimraf} = require('./utils'); -const inputDirPath = __dirname + '/input'; +const path = require('path'); +const inputDirPath = path.join(__dirname, '/input'); describe('autoinstall', function() { beforeEach(async function() { // Setup (clear the input dir and move integration test in) await rimraf(inputDirPath, {}); - await ncp(__dirname + '/integration/babel-default', inputDirPath); + await ncp(path.join(__dirname, '/integration/babel-default'), inputDirPath); }); it('should install lodash using npm and save dev dependency to package.json', async function() { diff --git a/test/bundler.js b/test/bundler.js index 39b3ed0a60e..7534f3a5603 100644 --- a/test/bundler.js +++ b/test/bundler.js @@ -1,10 +1,13 @@ const assert = require('assert'); const sinon = require('sinon'); +const path = require('path'); const {assertBundleTree, bundle, bundler, nextBundle} = require('./utils'); describe('bundler', function() { it('should bundle once before exporting middleware', async function() { - let b = bundler(__dirname + '/integration/bundler-middleware/index.js'); + let b = bundler( + path.join(__dirname, '/integration/bundler-middleware/index.js') + ); b.middleware(); await nextBundle(b); @@ -12,7 +15,7 @@ describe('bundler', function() { }); it('should defer bundling if a bundle is pending', async () => { - const b = bundler(__dirname + '/integration/html/index.html'); + const b = bundler(path.join(__dirname, '/integration/html/index.html')); b.pending = true; // bundle in progress const spy = sinon.spy(b, 'bundle'); @@ -30,7 +33,7 @@ describe('bundler', function() { }); it('should enforce asset type path to be a string', () => { - const b = bundler(__dirname + '/integration/html/index.html'); + const b = bundler(path.join(__dirname, '/integration/html/index.html')); assert.throws(() => { b.addAssetType('.ext', {}); @@ -38,7 +41,7 @@ describe('bundler', function() { }); it('should enforce setup before bundling', () => { - const b = bundler(__dirname + '/integration/html/index.html'); + const b = bundler(path.join(__dirname, '/integration/html/index.html')); b.farm = true; // truthy assert.throws(() => { @@ -52,8 +55,8 @@ describe('bundler', function() { it('should support multiple entry points', async function() { let b = await bundle([ - __dirname + '/integration/multi-entry/one.html', - __dirname + '/integration/multi-entry/two.html' + path.join(__dirname, '/integration/multi-entry/one.html'), + path.join(__dirname, '/integration/multi-entry/two.html') ]); await assertBundleTree(b, [ @@ -76,7 +79,9 @@ describe('bundler', function() { }); it('should support multiple entry points as a glob', async function() { - let b = await bundle(__dirname + '/integration/multi-entry/*.html'); + let b = await bundle( + path.join(__dirname, '/integration/multi-entry/*.html') + ); await assertBundleTree(b, [ { diff --git a/test/contentHashing.js b/test/contentHashing.js index 3288da325fd..b230e44556b 100644 --- a/test/contentHashing.js +++ b/test/contentHashing.js @@ -1,63 +1,73 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, rimraf, ncp} = require('./utils'); describe('content hashing', function() { beforeEach(async function() { - await rimraf(__dirname + '/input'); + await rimraf(path.join(__dirname, '/input')); }); it('should update content hash when content changes', async function() { - await ncp(__dirname + '/integration/html-css', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/html-css'), + path.join(__dirname, '/input') + ); - await bundle(__dirname + '/input/index.html', { + await bundle(path.join(__dirname, '/input/index.html'), { production: true }); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); let filename = html.match( // )[1]; - assert(await fs.exists(__dirname + '/dist/' + filename)); + assert(await fs.exists(path.join(__dirname, '/dist/', filename))); await fs.writeFile( - __dirname + '/input/index.css', + path.join(__dirname, '/input/index.css'), 'body { background: green }' ); - await bundle(__dirname + '/input/index.html', { + await bundle(path.join(__dirname, '/input/index.html'), { production: true }); - html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + html = await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8'); let newFilename = html.match( // )[1]; - assert(await fs.exists(__dirname + '/dist/' + newFilename)); + assert(await fs.exists(path.join(__dirname, '/dist/', newFilename))); assert.notEqual(filename, newFilename); }); it('should update content hash when raw asset changes', async function() { - await ncp(__dirname + '/integration/import-raw', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/import-raw'), + path.join(__dirname, '/input') + ); - await bundle(__dirname + '/input/index.js', { + await bundle(path.join(__dirname, '/input/index.js'), { production: true }); - let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); let filename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1]; - assert(await fs.exists(__dirname + '/dist/' + filename)); + assert(await fs.exists(path.join(__dirname, '/dist/', filename))); - await fs.writeFile(__dirname + '/input/test.txt', 'hello world'); + await fs.writeFile(path.join(__dirname, '/input/test.txt'), 'hello world'); - await bundle(__dirname + '/input/index.js', { + await bundle(path.join(__dirname, '/input/index.js'), { production: true }); - js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); let newFilename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1]; - assert(await fs.exists(__dirname + '/dist/' + newFilename)); + assert(await fs.exists(path.join(__dirname, '/dist/', newFilename))); assert.notEqual(filename, newFilename); }); diff --git a/test/css.js b/test/css.js index a880dc85280..feeba213645 100644 --- a/test/css.js +++ b/test/css.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, run, assertBundleTree, rimraf, ncp} = require('./utils'); describe('css', function() { it('should produce two bundles when importing a CSS file', async function() { - let b = await bundle(__dirname + '/integration/css/index.js'); + let b = await bundle(path.join(__dirname, '/integration/css/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -27,7 +28,9 @@ describe('css', function() { }); it('should support loading a CSS bundle along side dynamic imports', async function() { - let b = await bundle(__dirname + '/integration/dynamic-css/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/dynamic-css/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -71,7 +74,9 @@ describe('css', function() { }); it('should support importing CSS from a CSS file', async function() { - let b = await bundle(__dirname + '/integration/css-import/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/css-import/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -93,7 +98,10 @@ describe('css', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.local')); assert(css.includes('.other')); assert(/@media print {\s*.other/.test(css)); @@ -101,7 +109,7 @@ describe('css', function() { }); it('should support linking to assets with url() from CSS', async function() { - let b = await bundle(__dirname + '/integration/css-url/index.js'); + let b = await bundle(path.join(__dirname, '/integration/css-url/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -127,7 +135,10 @@ describe('css', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(/url\("test\.[0-9a-f]+\.woff2"\)/.test(css)); assert(css.includes('url("http://google.com")')); assert(css.includes('.index')); @@ -138,15 +149,22 @@ describe('css', function() { assert( await fs.exists( - __dirname + '/dist/' + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + path.join( + __dirname, + '/dist/', + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + ) ) ); }); it('should support linking to assets with url() from CSS in production', async function() { - let b = await bundle(__dirname + '/integration/css-url/index.js', { - production: true - }); + let b = await bundle( + path.join(__dirname, '/integration/css-url/index.js'), + { + production: true + } + ); await assertBundleTree(b, { name: 'index.js', @@ -172,7 +190,10 @@ describe('css', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(/url\(test\.[0-9a-f]+\.woff2\)/.test(css), 'woff ext found in css'); assert(css.includes('url(http://google.com)'), 'url() found'); assert(css.includes('.index'), '.index found'); @@ -183,13 +204,17 @@ describe('css', function() { assert( await fs.exists( - __dirname + '/dist/' + css.match(/url\((test\.[0-9a-f]+\.woff2)\)/)[1] + path.join( + __dirname, + '/dist/', + css.match(/url\((test\.[0-9a-f]+\.woff2)\)/)[1] + ) ) ); }); it('should support transforming with postcss', async function() { - let b = await bundle(__dirname + '/integration/postcss/index.js'); + let b = await bundle(path.join(__dirname, '/integration/postcss/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -214,13 +239,20 @@ describe('css', function() { let cssClass = value.match(/(_index_[0-9a-z]+_1)/)[1]; - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes(`.${cssClass}`)); }); it('should support transforming with postcss twice with the same result', async function() { - let b = await bundle(__dirname + '/integration/postcss-plugins/index.js'); - let c = await bundle(__dirname + '/integration/postcss-plugins/index2.js'); + let b = await bundle( + path.join(__dirname, '/integration/postcss-plugins/index.js') + ); + let c = await bundle( + path.join(__dirname, '/integration/postcss-plugins/index2.js') + ); let [run1, run2] = await Promise.all([await run(b), await run(c)]); @@ -228,24 +260,33 @@ describe('css', function() { }); it('should minify CSS in production mode', async function() { - let b = await bundle(__dirname + '/integration/cssnano/index.js', { - production: true - }); + let b = await bundle( + path.join(__dirname, '/integration/cssnano/index.js'), + { + production: true + } + ); let output = await run(b); assert.equal(typeof output, 'function'); assert.equal(output(), 3); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.local')); assert(css.includes('.index')); assert(!css.includes('\n')); }); it('should automatically install postcss plugins with npm if needed', async function() { - await rimraf(__dirname + '/input'); - await ncp(__dirname + '/integration/autoinstall/npm', __dirname + '/input'); - await bundle(__dirname + '/input/index.css'); + await rimraf(path.join(__dirname, '/input')); + await ncp( + path.join(__dirname, '/integration/autoinstall/npm'), + path.join(__dirname, '/input') + ); + await bundle(path.join(__dirname, '/input/index.css')); // cssnext was installed let pkg = require('./input/package.json'); @@ -255,17 +296,20 @@ describe('css', function() { assert(pkg.devDependencies['caniuse-lite']); // cssnext is applied - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('rgba')); }); it('should automatically install postcss plugins with yarn if needed', async function() { - await rimraf(__dirname + '/input'); + await rimraf(path.join(__dirname, '/input')); await ncp( - __dirname + '/integration/autoinstall/yarn', - __dirname + '/input' + path.join(__dirname, '/integration/autoinstall/yarn'), + path.join(__dirname, '/input') ); - await bundle(__dirname + '/input/index.css'); + await bundle(path.join(__dirname, '/input/index.css')); // cssnext was installed let pkg = require('./input/package.json'); @@ -275,11 +319,14 @@ describe('css', function() { assert(pkg.devDependencies['caniuse-lite']); // appveyor is not currently writing to the yarn.lock file and will require further investigation - // let lockfile = await fs.readFile(__dirname + '/input/yarn.lock', 'utf8'); + // let lockfile = await fs.readFile(path.join(__dirname, '/input/yarn.lock'), 'utf8'); // assert(lockfile.includes('postcss-cssnext')); // cssnext is applied - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('rgba')); }); }); diff --git a/test/encodedURI.js b/test/encodedURI.js index 2f470a51e3a..bcaee2be22e 100644 --- a/test/encodedURI.js +++ b/test/encodedURI.js @@ -1,10 +1,13 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, assertBundleTree} = require('./utils'); describe('encodedURI', function() { it('should support bundling files which names in encoded URI', async function() { - let b = await bundle(__dirname + '/integration/encodedURI/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/encodedURI/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -18,8 +21,8 @@ describe('encodedURI', function() { ] }); - let files = await fs.readdir(__dirname + '/dist'); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let files = await fs.readdir(path.join(__dirname, '/dist')); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); for (let file of files) { if (file !== 'index.html') { assert(html.includes(file)); diff --git a/test/fs-cache.js b/test/fs-cache.js index ddf3fcffd8a..feb1734eb32 100644 --- a/test/fs-cache.js +++ b/test/fs-cache.js @@ -92,7 +92,7 @@ describe('FSCache', () => { it('should invalidate when dependency included in parent changes', async () => { const cache = new FSCache({cacheDir: cachePath}); - await ncp(__dirname + '/integration/fs', inputPath); + await ncp(path.join(__dirname, '/integration/fs'), inputPath); const filePath = path.join(inputPath, 'test.txt'); await cache.write(__filename, { @@ -141,7 +141,7 @@ describe('FSCache', () => { const cache = new FSCache({cacheDir: cachePath}); const wildcardPath = path.join(inputPath, 'wildcard'); await fs.mkdirp(wildcardPath); - await ncp(__dirname + '/integration/fs', wildcardPath); + await ncp(path.join(__dirname, '/integration/fs'), wildcardPath); const filePath = path.join(wildcardPath, 'test.txt'); await cache.write(__filename, { diff --git a/test/fs.js b/test/fs.js index b5c2edb40b1..c3640d988e1 100644 --- a/test/fs.js +++ b/test/fs.js @@ -1,55 +1,68 @@ const assert = require('assert'); const fs = require('../src/utils/fs'); +const path = require('path'); const {bundle, run, assertBundleTree} = require('./utils'); describe('fs', function() { describe('--target=browser', function() { it('should inline a file as a string', async function() { - let b = await bundle(__dirname + '/integration/fs/index.js'); + let b = await bundle(path.join(__dirname, '/integration/fs/index.js')); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file as a buffer', async function() { - let b = await bundle(__dirname + '/integration/fs-buffer/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-buffer/index.js') + ); let output = await run(b); assert(output.constructor.name.includes('Buffer')); assert.equal(output.length, 5); }); it('should inline a file with fs require alias', async function() { - let b = await bundle(__dirname + '/integration/fs-alias/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-alias/index.js') + ); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file with fs require inline', async function() { - let b = await bundle(__dirname + '/integration/fs-inline/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-inline/index.js') + ); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file with fs require assignment', async function() { - let b = await bundle(__dirname + '/integration/fs-assign/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-assign/index.js') + ); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file with fs require assignment alias', async function() { - let b = await bundle(__dirname + '/integration/fs-assign-alias/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-assign-alias/index.js') + ); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file with fs require destructure', async function() { - let b = await bundle(__dirname + '/integration/fs-destructure/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/fs-destructure/index.js') + ); let output = await run(b); assert.equal(output, 'hello'); }); it('should inline a file with fs require destructure assignment', async function() { let b = await bundle( - __dirname + '/integration/fs-destructure-assign/index.js' + path.join(__dirname, '/integration/fs-destructure-assign/index.js') ); let output = await run(b); assert.equal(output, 'hello'); @@ -57,7 +70,7 @@ describe('fs', function() { it('should not evaluate fs calls when package.browser.fs is false', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/ignore-fs.js' + path.join(__dirname, '/integration/resolve-entries/ignore-fs.js') ); await assertBundleTree(b, { @@ -80,7 +93,7 @@ describe('fs', function() { // TODO: check if the logger has warned the user it('should ignore fs calls when the filename is not evaluable', async function() { let b = await bundle( - __dirname + '/integration/fs-file-non-evaluable/index.js' + path.join(__dirname, '/integration/fs-file-non-evaluable/index.js') ); let thrown = false; @@ -97,7 +110,7 @@ describe('fs', function() { it('should ignore fs calls when the options are not evaluable', async function() { let b = await bundle( - __dirname + '/integration/fs-options-non-evaluable/index.js' + path.join(__dirname, '/integration/fs-options-non-evaluable/index.js') ); let thrown = false; @@ -115,7 +128,7 @@ describe('fs', function() { describe('--target=node', function() { it('should leave an attempt to read a file unchanged', async function() { - let b = await bundle(__dirname + '/integration/fs/index.js', { + let b = await bundle(path.join(__dirname, '/integration/fs/index.js'), { target: 'node' }); @@ -132,7 +145,7 @@ describe('fs', function() { assert((await fs.readFile(b.name)).includes("require('fs')")); assert((await fs.readFile(b.name)).includes('readFileSync')); - await fs.writeFile(__dirname + '/dist/test.txt', 'hey'); + await fs.writeFile(path.join(__dirname, '/dist/test.txt'), 'hey'); let output = await run(b); assert.equal(output, 'hey'); }); @@ -140,7 +153,7 @@ describe('fs', function() { describe('--target=electron', function() { it('should leave an attempt to read a file unchanged', async function() { - let b = await bundle(__dirname + '/integration/fs/index.js', { + let b = await bundle(path.join(__dirname, '/integration/fs/index.js'), { target: 'electron' }); @@ -157,7 +170,7 @@ describe('fs', function() { assert((await fs.readFile(b.name)).includes("require('fs')")); assert((await fs.readFile(b.name)).includes('readFileSync')); - await fs.writeFile(__dirname + '/dist/test.txt', 'hey'); + await fs.writeFile(path.join(__dirname, '/dist/test.txt'), 'hey'); let output = await run(b); assert.equal(output, 'hey'); }); diff --git a/test/glob.js b/test/glob.js index 014b25725d7..f63268010bd 100644 --- a/test/glob.js +++ b/test/glob.js @@ -1,10 +1,11 @@ const assert = require('assert'); const fs = require('../src/utils/fs'); +const path = require('path'); const {bundle, run, assertBundleTree} = require('./utils'); describe('glob', function() { it('should require a glob of files', async function() { - let b = await bundle(__dirname + '/integration/glob/index.js'); + let b = await bundle(path.join(__dirname, '/integration/glob/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -22,7 +23,9 @@ describe('glob', function() { }); it('should require nested directories with a glob', async function() { - let b = await bundle(__dirname + '/integration/glob-deep/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/glob-deep/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -40,7 +43,9 @@ describe('glob', function() { }); it('should support importing a glob of CSS files', async function() { - let b = await bundle(__dirname + '/integration/glob-css/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/glob-css/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -61,7 +66,10 @@ describe('glob', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.local')); assert(css.includes('.other')); assert(css.includes('.index')); diff --git a/test/glsl.js b/test/glsl.js index e92e0a66986..f28f67e5cfb 100644 --- a/test/glsl.js +++ b/test/glsl.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); -const {bundle, run, assertBundleTree} = require('./utils'); +const {bundle, run, assertBundleTree, normaliseNewlines} = require('./utils'); describe('glsl', function() { it('should support requiring GLSL files via glslify', async function() { - let b = await bundle(__dirname + '/integration/glsl/index.js'); + let b = await bundle(path.join(__dirname, '/integration/glsl/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -17,7 +18,7 @@ describe('glsl', function() { }); let shader = await fs.readFile( - __dirname + '/integration/glsl/compiled.glsl', + path.join(__dirname, '/integration/glsl/compiled.glsl'), 'utf8' ); @@ -25,7 +26,9 @@ describe('glsl', function() { assert.equal(typeof output, 'function'); assert.ok( output().reduce((acc, requiredShader) => { - return acc && shader === requiredShader; + return ( + acc && normaliseNewlines(shader) === normaliseNewlines(requiredShader) + ); }, true) ); }); diff --git a/test/graphql.js b/test/graphql.js index 136eb030d70..acab8202112 100644 --- a/test/graphql.js +++ b/test/graphql.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const gql = require('graphql-tag'); const {bundle, run, assertBundleTree} = require('./utils'); describe('graphql', function() { it('should support requiring graphql files', async function() { - let b = await bundle(__dirname + '/integration/graphql/index.js'); + let b = await bundle(path.join(__dirname, '/integration/graphql/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -37,7 +38,9 @@ describe('graphql', function() { }); it('should support importing other graphql files from a graphql file', async function() { - let b = await bundle(__dirname + '/integration/graphql-import/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/graphql-import/index.js') + ); await assertBundleTree(b, { name: 'index.js', diff --git a/test/hmr.js b/test/hmr.js index 776aae39cf0..812ed1ed805 100644 --- a/test/hmr.js +++ b/test/hmr.js @@ -10,7 +10,7 @@ describe('hmr', function() { let b, ws, stub; beforeEach(async function() { stub = sinon.stub(console, 'clear'); - await rimraf(__dirname + '/input'); + await rimraf(path.join(__dirname, '/input')); }); afterEach(async function() { @@ -40,9 +40,15 @@ describe('hmr', function() { } it('should emit an HMR update for the file that changed', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); await b.bundle(); ws = new WebSocket('ws://localhost:' + b.options.hmrPort); @@ -54,7 +60,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5;\nexports.b = 5;' ); @@ -68,9 +74,12 @@ describe('hmr', function() { }); it('should not enable HMR for --target=node', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', { + b = bundler(path.join(__dirname, '/input/index.js'), { watch: true, hmr: true, target: 'node' @@ -85,9 +94,12 @@ describe('hmr', function() { }); it('should enable HMR for --target=electron', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', { + b = bundler(path.join(__dirname, '/input/index.js'), { watch: true, hmr: true, target: 'electron' @@ -103,7 +115,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5; exports.b = 5;' ); @@ -117,9 +129,15 @@ describe('hmr', function() { }); it('should emit an HMR update for all new dependencies along with the changed file', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); await b.bundle(); ws = new WebSocket('ws://localhost:' + b.options.hmrPort); @@ -131,7 +149,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"); exports.a = 5; exports.b = 5;' ); @@ -143,9 +161,15 @@ describe('hmr', function() { }); it('should emit an HMR error on bundle failure', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); await b.bundle(); ws = new WebSocket('ws://localhost:' + b.options.hmrPort); @@ -157,7 +181,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"; exports.a = 5; exports.b = 5;' ); @@ -179,9 +203,15 @@ describe('hmr', function() { }); it('should emit an HMR error to new connections after a bundle failure', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); await b.bundle(); if (process.platform === 'win32') { @@ -189,7 +219,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"; exports.a = 5; exports.b = 5;' ); await nextEvent(b, 'buildEnd'); @@ -201,9 +231,15 @@ describe('hmr', function() { }); it('should emit an HMR error-resolved on build after error', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); await b.bundle(); ws = new WebSocket('ws://localhost:' + b.options.hmrPort); @@ -215,7 +251,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"; exports.a = 5; exports.b = 5;' ); @@ -227,7 +263,7 @@ describe('hmr', function() { const secondBuildEnd = nextEvent(b, 'buildEnd'); await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"); exports.a = 5; exports.b = 5;' ); @@ -238,9 +274,15 @@ describe('hmr', function() { }); it('should accept HMR updates in the runtime', async function() { - await ncp(__dirname + '/integration/hmr', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/hmr'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); let bundle = await b.bundle(); let outputs = []; @@ -257,7 +299,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5; exports.b = 5;' ); @@ -266,9 +308,15 @@ describe('hmr', function() { }); it('should call dispose and accept callbacks', async function() { - await ncp(__dirname + '/integration/hmr-callbacks', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/hmr-callbacks'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); let bundle = await b.bundle(); let outputs = []; let moduleId = ''; @@ -289,7 +337,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5; exports.b = 5;' ); @@ -304,9 +352,15 @@ describe('hmr', function() { }); it('should work across bundles', async function() { - await ncp(__dirname + '/integration/hmr-dynamic', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/hmr-dynamic'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); let bundle = await b.bundle(); let outputs = []; @@ -324,7 +378,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5; exports.b = 5;' ); @@ -334,9 +388,15 @@ describe('hmr', function() { }); it('should log emitted errors and show an error overlay', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); let bundle = await b.bundle(); let logs = []; @@ -360,7 +420,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"; exports.a = 5; exports.b = 5;' ); await nextEvent(b, 'buildEnd'); @@ -372,9 +432,15 @@ describe('hmr', function() { }); it('should log when errors resolve', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', {watch: true, hmr: true}); + b = bundler(path.join(__dirname, '/input/index.js'), { + watch: true, + hmr: true + }); let bundle = await b.bundle(); let logs = []; @@ -402,7 +468,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"; exports.a = 5; exports.b = 5;' ); await nextEvent(b, 'buildEnd'); @@ -411,7 +477,7 @@ describe('hmr', function() { assert(appendSpy.called); await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'require("fs"); exports.a = 5; exports.b = 5;' ); await nextEvent(b, 'buildEnd'); @@ -425,9 +491,12 @@ describe('hmr', function() { }); it('should make a secure connection', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', { + b = bundler(path.join(__dirname, '/input/index.js'), { watch: true, hmr: true, https: true @@ -445,7 +514,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5;\nexports.b = 5;' ); @@ -459,14 +528,17 @@ describe('hmr', function() { }); it('should make a secure connection with custom certificate', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp( + path.join(__dirname, '/integration/commonjs'), + path.join(__dirname, '/input') + ); - b = bundler(__dirname + '/input/index.js', { + b = bundler(path.join(__dirname, '/input/index.js'), { watch: true, hmr: true, https: { - key: __dirname + '/integration/https/private.pem', - cert: __dirname + '/integration/https/primary.crt' + key: path.join(__dirname, '/integration/https/private.pem'), + cert: path.join(__dirname, '/integration/https/primary.crt') } }); await b.bundle(); @@ -482,7 +554,7 @@ describe('hmr', function() { } await fs.writeFile( - __dirname + '/input/local.js', + path.join(__dirname, '/input/local.js'), 'exports.a = 5;\nexports.b = 5;' ); diff --git a/test/html.js b/test/html.js index f2df83c6f2f..90fac806d0d 100644 --- a/test/html.js +++ b/test/html.js @@ -5,7 +5,7 @@ const path = require('path'); describe('html', function() { it('should support bundling HTML', async function() { - let b = await bundle(__dirname + '/integration/html/index.html'); + let b = await bundle(path.join(__dirname, '/integration/html/index.html')); await assertBundleTree(b, { name: 'index.html', @@ -44,8 +44,8 @@ describe('html', function() { ] }); - let files = await fs.readdir(__dirname + '/dist'); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let files = await fs.readdir(path.join(__dirname, '/dist')); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); for (let file of files) { let ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0]; if (file !== 'index.html' && ext !== '.map') { @@ -55,7 +55,9 @@ describe('html', function() { }); it('should find href attr when not first', async function() { - let b = await bundle(__dirname + '/integration/html-attr-order/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-attr-order/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -71,7 +73,9 @@ describe('html', function() { }); it('should support transforming HTML with posthtml', async function() { - let b = await bundle(__dirname + '/integration/posthtml/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/posthtml/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -79,12 +83,14 @@ describe('html', function() { childBundles: [] }); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); assert(html.includes('

Other page

')); }); it('should find assets inside posthtml', async function() { - let b = await bundle(__dirname + '/integration/posthtml-assets/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/posthtml-assets/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -105,7 +111,7 @@ describe('html', function() { it('should add dependencies referenced by posthtml-include', async () => { const b = await bundle( - __dirname + '/integration/posthtml-assets/index.html' + path.join(__dirname, '/integration/posthtml-assets/index.html') ); const asset = b.assets.values().next().value; const other = path.join( @@ -118,7 +124,7 @@ describe('html', function() { it('should add dependencies referenced by plugins', async () => { const b = await bundle( - __dirname + '/integration/posthtml-plugin-deps/index.html' + path.join(__dirname, '/integration/posthtml-plugin-deps/index.html') ); const asset = b.assets.values().next().value; const other = path.join( @@ -130,7 +136,9 @@ describe('html', function() { }); it('should insert sibling CSS bundles for JS files in the HEAD', async function() { - let b = await bundle(__dirname + '/integration/html-css/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-css/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -153,7 +161,7 @@ describe('html', function() { ] }); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); assert( //.test( html @@ -162,7 +170,9 @@ describe('html', function() { }); it('should insert sibling bundles before body element if no HEAD', async function() { - let b = await bundle(__dirname + '/integration/html-css-head/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-css-head/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -185,7 +195,7 @@ describe('html', function() { ] }); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); assert( /\s*\s*/.test( html @@ -194,9 +204,12 @@ describe('html', function() { }); it('should insert sibling JS bundles for CSS files in the HEAD', async function() { - let b = await bundle(__dirname + '/integration/html-css-js/index.html', { - hmr: true - }); + let b = await bundle( + path.join(__dirname, '/integration/html-css-js/index.html'), + { + hmr: true + } + ); await assertBundleTree(b, { name: 'index.html', @@ -224,13 +237,13 @@ describe('html', function() { ] }); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); assert(/') ); }); it('should not prepend the public path to hash links', async function() { - await bundle(__dirname + '/integration/html/index.html'); + await bundle(path.join(__dirname, '/integration/html/index.html')); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); assert(html.includes('')); }); it('should detect virtual paths', async function() { let b = await bundle( - __dirname + '/integration/html-virtualpath/index.html' + path.join(__dirname, '/integration/html-virtualpath/index.html') ); await assertBundleTree(b, { @@ -348,30 +382,36 @@ describe('html', function() { }); it('should not update root/main file in the bundles', async function() { - await bundle(__dirname + '/integration/html-root/index.html'); + await bundle(path.join(__dirname, '/integration/html-root/index.html')); - let files = await fs.readdir(__dirname + '/dist'); + let files = await fs.readdir(path.join(__dirname, '/dist')); for (let file of files) { if (file !== 'index.html' && file.endsWith('.html')) { - let html = await fs.readFile(__dirname + '/dist/' + file); + let html = await fs.readFile(path.join(__dirname, '/dist/', file)); assert(html.includes('index.html')); } } }); it('should conserve the spacing in the HTML tags', async function() { - await bundle(__dirname + '/integration/html/index.html', { + await bundle(path.join(__dirname, '/integration/html/index.html'), { production: true }); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); assert(/hello<\/i> world<\/i>/.test(html)); }); it('should support child bundles of different types', async function() { let b = await bundle( - __dirname + '/integration/child-bundle-different-types/index.html' + path.join( + __dirname, + '/integration/child-bundle-different-types/index.html' + ) ); await assertBundleTree(b, { @@ -407,7 +447,9 @@ describe('html', function() { }); it('should support circular dependencies', async function() { - let b = await bundle(__dirname + '/integration/circular/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/circular/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -447,7 +489,9 @@ describe('html', function() { }); it('should support bundling HTM', async function() { - let b = await bundle(__dirname + '/integration/htm-extension/index.htm'); + let b = await bundle( + path.join(__dirname, '/integration/htm-extension/index.htm') + ); await assertBundleTree(b, { name: 'index.html', @@ -468,7 +512,9 @@ describe('html', function() { }); it('should detect srcset attribute', async function() { - let b = await bundle(__dirname + '/integration/html-srcset/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-srcset/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -495,7 +541,7 @@ describe('html', function() { it('should detect srcset attribute of source element', async function() { let b = await bundle( - __dirname + '/integration/html-source-srcset/index.html' + path.join(__dirname, '/integration/html-source-srcset/index.html') ); await assertBundleTree(b, { @@ -522,7 +568,9 @@ describe('html', function() { }); it('should support webmanifest', async function() { - let b = await bundle(__dirname + '/integration/webmanifest/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/webmanifest/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -544,7 +592,9 @@ describe('html', function() { }); it('should bundle svg files correctly', async function() { - let b = await bundle(__dirname + '/integration/html-svg/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-svg/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -559,7 +609,9 @@ describe('html', function() { }); it('should support data attribute of object element', async function() { - let b = await bundle(__dirname + '/integration/html-object/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/html-object/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -575,7 +627,9 @@ describe('html', function() { }); it('should resolve assets containing spaces', async function() { - let b = await bundle(__dirname + '/integration/resolve-spaces/index.html'); + let b = await bundle( + path.join(__dirname, '/integration/resolve-spaces/index.html') + ); await assertBundleTree(b, { name: 'index.html', @@ -591,9 +645,12 @@ describe('html', function() { }); it('should process inline JS', async function() { - let b = await bundle(__dirname + '/integration/html-inline-js/index.html', { - production: true - }); + let b = await bundle( + path.join(__dirname, '/integration/html-inline-js/index.html'), + { + production: true + } + ); const bundleContent = (await fs.readFile(b.name)).toString(); assert(!bundleContent.includes('someArgument')); @@ -601,7 +658,7 @@ describe('html', function() { it('should process inline styles', async function() { let b = await bundle( - __dirname + '/integration/html-inline-styles/index.html', + path.join(__dirname, '/integration/html-inline-styles/index.html'), {production: true} ); @@ -625,7 +682,7 @@ describe('html', function() { it('should process inline styles using lang', async function() { let b = await bundle( - __dirname + '/integration/html-inline-sass/index.html', + path.join(__dirname, '/integration/html-inline-sass/index.html'), {production: true} ); @@ -634,14 +691,17 @@ describe('html', function() { assets: ['index.html'] }); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); assert(html.includes('')); }); it('should process inline non-js scripts', async function() { let b = await bundle( - __dirname + '/integration/html-inline-coffeescript/index.html', + path.join(__dirname, '/integration/html-inline-coffeescript/index.html'), {production: true} ); @@ -650,14 +710,17 @@ describe('html', function() { assets: ['index.html'] }); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); assert(html.includes('alert("Hello, World!")')); }); it('should handle inline css with @imports', async function() { let b = await bundle( - __dirname + '/integration/html-inline-css-import/index.html', + path.join(__dirname, '/integration/html-inline-css-import/index.html'), {production: true} ); @@ -672,7 +735,10 @@ describe('html', function() { ] }); - let html = await fs.readFile(__dirname + '/dist/index.html', 'utf8'); + let html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf8' + ); assert(html.includes('@import')); }); @@ -680,7 +746,7 @@ describe('html', function() { let err; try { await bundle( - __dirname + '/integration/html-inline-js-require/index.html', + path.join(__dirname, '/integration/html-inline-js-require/index.html'), {production: true} ); } catch (e) { diff --git a/test/integration/babel-node-modules-source/node_modules/foo b/test/integration/babel-node-modules-source/node_modules/foo deleted file mode 120000 index 61d898a3a60..00000000000 --- a/test/integration/babel-node-modules-source/node_modules/foo +++ /dev/null @@ -1 +0,0 @@ -../packages/foo \ No newline at end of file diff --git a/test/integration/commonjs-with-symlinks/src/symlinked_local.js b/test/integration/commonjs-with-symlinks/src/symlinked_local.js deleted file mode 120000 index ea037a11afd..00000000000 --- a/test/integration/commonjs-with-symlinks/src/symlinked_local.js +++ /dev/null @@ -1 +0,0 @@ -../local.js \ No newline at end of file diff --git a/test/integration/resolver/node_modules/source b/test/integration/resolver/node_modules/source deleted file mode 120000 index b069b24161e..00000000000 --- a/test/integration/resolver/node_modules/source +++ /dev/null @@ -1 +0,0 @@ -../packages/source \ No newline at end of file diff --git a/test/integration/resolver/node_modules/source-alias b/test/integration/resolver/node_modules/source-alias deleted file mode 120000 index ab07af6a104..00000000000 --- a/test/integration/resolver/node_modules/source-alias +++ /dev/null @@ -1 +0,0 @@ -../packages/source-alias \ No newline at end of file diff --git a/test/integration/resolver/node_modules/source-alias-glob b/test/integration/resolver/node_modules/source-alias-glob deleted file mode 120000 index 124948a55e2..00000000000 --- a/test/integration/resolver/node_modules/source-alias-glob +++ /dev/null @@ -1 +0,0 @@ -../packages/source-alias-glob \ No newline at end of file diff --git a/test/javascript.js b/test/javascript.js index aef22a52c9b..b1c04773936 100644 --- a/test/javascript.js +++ b/test/javascript.js @@ -1,12 +1,15 @@ const assert = require('assert'); const fs = require('../src/utils/fs'); const path = require('path'); -const {bundle, run, assertBundleTree, deferred} = require('./utils'); +const {bundle, run, assertBundleTree, deferred, ncp} = require('./utils'); const {mkdirp} = require('../src/utils/fs'); +const {symlinkSync} = require('fs'); describe('javascript', function() { it('should produce a basic JS bundle with CommonJS requires', async function() { - let b = await bundle(__dirname + '/integration/commonjs/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/commonjs/index.js') + ); assert.equal(b.assets.size, 8); assert.equal(b.childBundles.size, 1); @@ -17,7 +20,7 @@ describe('javascript', function() { }); it('should produce a basic JS bundle with ES6 imports', async function() { - let b = await bundle(__dirname + '/integration/es6/index.js'); + let b = await bundle(path.join(__dirname, '/integration/es6/index.js')); assert.equal(b.assets.size, 8); assert.equal(b.childBundles.size, 1); @@ -30,7 +33,10 @@ describe('javascript', function() { it('should produce a basic JS bundle with object rest spread support', async function() { let b = await bundle( - __dirname + '/integration/object-rest-spread/object-rest-spread.js' + path.join( + __dirname, + '/integration/object-rest-spread/object-rest-spread.js' + ) ); assert.equal(b.assets.size, 1); @@ -46,9 +52,12 @@ describe('javascript', function() { }); it('should bundle node_modules on --target=browser', async function() { - let b = await bundle(__dirname + '/integration/node_require/main.js', { - target: 'browser' - }); + let b = await bundle( + path.join(__dirname, '/integration/node_require/main.js'), + { + target: 'browser' + } + ); await assertBundleTree(b, { name: 'main.js', @@ -61,18 +70,21 @@ describe('javascript', function() { }); it('should not bundle node_modules on --target=node', async function() { - let b = await bundle(__dirname + '/integration/node_require/main.js', { - target: 'node' - }); + let b = await bundle( + path.join(__dirname, '/integration/node_require/main.js'), + { + target: 'node' + } + ); await assertBundleTree(b, { name: 'main.js', assets: ['main.js', 'local.js'] }); - await mkdirp(__dirname + '/dist/node_modules/testmodule'); + await mkdirp(path.join(__dirname, '/dist/node_modules/testmodule')); await fs.writeFile( - __dirname + '/dist/node_modules/testmodule/index.js', + path.join(__dirname, '/dist/node_modules/testmodule/index.js'), 'exports.a = 5;' ); @@ -82,18 +94,21 @@ describe('javascript', function() { }); it('should not bundle node_modules on --target=electron', async function() { - let b = await bundle(__dirname + '/integration/node_require/main.js', { - target: 'electron' - }); + let b = await bundle( + path.join(__dirname, '/integration/node_require/main.js'), + { + target: 'electron' + } + ); await assertBundleTree(b, { name: 'main.js', assets: ['main.js', 'local.js'] }); - await mkdirp(__dirname + '/dist/node_modules/testmodule'); + await mkdirp(path.join(__dirname, '/dist/node_modules/testmodule')); await fs.writeFile( - __dirname + '/dist/node_modules/testmodule/index.js', + path.join(__dirname, '/dist/node_modules/testmodule/index.js'), 'exports.a = 5;' ); @@ -103,10 +118,13 @@ describe('javascript', function() { }); it('should bundle node_modules on --target=node and --bundle-node-modules', async function() { - let b = await bundle(__dirname + '/integration/node_require/main.js', { - target: 'node', - bundleNodeModules: true - }); + let b = await bundle( + path.join(__dirname, '/integration/node_require/main.js'), + { + target: 'node', + bundleNodeModules: true + } + ); await assertBundleTree(b, { name: 'main.js', @@ -119,10 +137,13 @@ describe('javascript', function() { }); it('should bundle node_modules on --target=electron and --bundle-node-modules', async function() { - let b = await bundle(__dirname + '/integration/node_require/main.js', { - target: 'electron', - bundleNodeModules: true - }); + let b = await bundle( + path.join(__dirname, '/integration/node_require/main.js'), + { + target: 'electron', + bundleNodeModules: true + } + ); await assertBundleTree(b, { name: 'main.js', @@ -135,7 +156,9 @@ describe('javascript', function() { }); it('should produce a JS bundle with default exports and no imports', async function() { - let b = await bundle(__dirname + '/integration/es6-default-only/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/es6-default-only/index.js') + ); assert.equal(b.assets.size, 1); assert.equal(b.childBundles.size, 1); @@ -147,9 +170,12 @@ describe('javascript', function() { }); it('should split bundles when a dynamic import is used with --target=browser', async function() { - let b = await bundle(__dirname + '/integration/dynamic/index.js', { - target: 'browser' - }); + let b = await bundle( + path.join(__dirname, '/integration/dynamic/index.js'), + { + target: 'browser' + } + ); await assertBundleTree(b, { name: 'index.js', @@ -175,9 +201,12 @@ describe('javascript', function() { }); it('should split bundles when a dynamic import is used with --target=node', async function() { - let b = await bundle(__dirname + '/integration/dynamic/index.js', { - target: 'node' - }); + let b = await bundle( + path.join(__dirname, '/integration/dynamic/index.js'), + { + target: 'node' + } + ); await assertBundleTree(b, { name: 'index.js', @@ -203,7 +232,7 @@ describe('javascript', function() { }); it('should support bundling workers', async function() { - let b = await bundle(__dirname + '/integration/workers/index.js'); + let b = await bundle(path.join(__dirname, '/integration/workers/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -242,7 +271,7 @@ describe('javascript', function() { it('should support bundling workers with different order', async function() { let b = await bundle( - __dirname + '/integration/workers/index-alternative.js' + path.join(__dirname, '/integration/workers/index-alternative.js') ); assertBundleTree(b, { @@ -286,7 +315,9 @@ describe('javascript', function() { }); it('should support bundling service-workers', async function() { - let b = await bundle(__dirname + '/integration/service-worker/a/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/service-worker/a/index.js') + ); assertBundleTree(b, { name: 'index.js', @@ -316,9 +347,12 @@ describe('javascript', function() { }); it('should support bundling workers with circular dependencies', async function() { - let b = await bundle(__dirname + '/integration/worker-circular/index.js', { - sourceMaps: false - }); + let b = await bundle( + path.join(__dirname, '/integration/worker-circular/index.js'), + { + sourceMaps: false + } + ); await assertBundleTree(b, { name: 'index.js', @@ -333,7 +367,7 @@ describe('javascript', function() { it('should dynamic import files which import raw files', async function() { let b = await bundle( - __dirname + '/integration/dynamic-references-raw/index.js' + path.join(__dirname, '/integration/dynamic-references-raw/index.js') ); await assertBundleTree(b, { @@ -363,7 +397,9 @@ describe('javascript', function() { }); it('should return all exports as an object when using ES modules', async function() { - let b = await bundle(__dirname + '/integration/dynamic-esm/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/dynamic-esm/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -389,7 +425,9 @@ describe('javascript', function() { }); it('should hoist common dependencies into a parent bundle', async function() { - let b = await bundle(__dirname + '/integration/dynamic-hoist/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/dynamic-hoist/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -430,7 +468,9 @@ describe('javascript', function() { }); it('should not duplicate a module which is already in a parent bundle', async function() { - let b = await bundle(__dirname + '/integration/dynamic-hoist-dup/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/dynamic-hoist-dup/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -463,7 +503,7 @@ describe('javascript', function() { it('should support hoisting shared modules with async imports up multiple levels', async function() { let b = await bundle( - __dirname + '/integration/dynamic-hoist-deep/index.js', + path.join(__dirname, '/integration/dynamic-hoist-deep/index.js'), { sourceMaps: false } @@ -500,7 +540,7 @@ describe('javascript', function() { }); it('should support requiring JSON files', async function() { - let b = await bundle(__dirname + '/integration/json/index.js'); + let b = await bundle(path.join(__dirname, '/integration/json/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -518,7 +558,7 @@ describe('javascript', function() { }); it('should support requiring JSON5 files', async function() { - let b = await bundle(__dirname + '/integration/json5/index.js'); + let b = await bundle(path.join(__dirname, '/integration/json5/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -536,7 +576,9 @@ describe('javascript', function() { }); it('should support importing a URL to a raw asset', async function() { - let b = await bundle(__dirname + '/integration/import-raw/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/import-raw/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -556,11 +598,11 @@ describe('javascript', function() { let output = await run(b); assert.equal(typeof output, 'function'); assert(/^\/test\.[0-9a-f]+\.txt$/.test(output())); - assert(await fs.exists(__dirname + '/dist/' + output())); + assert(await fs.exists(path.join(__dirname, '/dist/', output()))); }); it('should minify JS in production mode', async function() { - let b = await bundle(__dirname + '/integration/uglify/index.js', { + let b = await bundle(path.join(__dirname, '/integration/uglify/index.js'), { production: true }); @@ -568,22 +610,22 @@ describe('javascript', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 3); - let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(!js.includes('local.a')); }); it('should use uglify config', async function() { - await bundle(__dirname + '/integration/uglify-config/index.js', { + await bundle(path.join(__dirname, '/integration/uglify-config/index.js'), { production: true }); - let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(!js.includes('console.log')); assert(!js.includes('// This is a comment')); }); it('should insert global variables when needed', async function() { - let b = await bundle(__dirname + '/integration/globals/index.js'); + let b = await bundle(path.join(__dirname, '/integration/globals/index.js')); let output = await run(b); assert.deepEqual(output(), { @@ -595,14 +637,16 @@ describe('javascript', function() { }); it('should handle re-declaration of the global constant', async function() { - let b = await bundle(__dirname + '/integration/global-redeclare/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/global-redeclare/index.js') + ); let output = await run(b); assert.deepEqual(output(), false); }); it('should not insert environment variables on --target=node', async function() { - let b = await bundle(__dirname + '/integration/env/index.js', { + let b = await bundle(path.join(__dirname, '/integration/env/index.js'), { target: 'node' }); @@ -612,7 +656,7 @@ describe('javascript', function() { }); it('should not insert environment variables on --target=electron', async function() { - let b = await bundle(__dirname + '/integration/env/index.js', { + let b = await bundle(path.join(__dirname, '/integration/env/index.js'), { target: 'electron' }); @@ -622,7 +666,7 @@ describe('javascript', function() { }); it('should insert environment variables on --target=browser', async function() { - let b = await bundle(__dirname + '/integration/env/index.js', { + let b = await bundle(path.join(__dirname, '/integration/env/index.js'), { target: 'browser' }); @@ -632,14 +676,16 @@ describe('javascript', function() { }); it('should insert environment variables from a file', async function() { - let b = await bundle(__dirname + '/integration/env-file/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/env-file/index.js') + ); let output = await run(b); assert.equal(output, 'bartest'); }); it('should support adding implicit dependencies', async function() { - let b = await bundle(__dirname + '/integration/json/index.js', { + let b = await bundle(path.join(__dirname, '/integration/json/index.js'), { delegate: { getImplicitDependencies(asset) { if (asset.basename === 'index.js') { @@ -669,7 +715,7 @@ describe('javascript', function() { }); it('should support requiring YAML files', async function() { - let b = await bundle(__dirname + '/integration/yaml/index.js'); + let b = await bundle(path.join(__dirname, '/integration/yaml/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -687,7 +733,7 @@ describe('javascript', function() { }); it('should support requiring TOML files', async function() { - let b = await bundle(__dirname + '/integration/toml/index.js'); + let b = await bundle(path.join(__dirname, '/integration/toml/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -705,7 +751,7 @@ describe('javascript', function() { }); it('should support requiring CoffeeScript files', async function() { - let b = await bundle(__dirname + '/integration/coffee/index.js'); + let b = await bundle(path.join(__dirname, '/integration/coffee/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -723,7 +769,9 @@ describe('javascript', function() { }); it('should resolve the browser field before main', async function() { - let b = await bundle(__dirname + '/integration/resolve-entries/browser.js'); + let b = await bundle( + path.join(__dirname, '/integration/resolve-entries/browser.js') + ); await assertBundleTree(b, { name: 'browser.js', @@ -743,7 +791,7 @@ describe('javascript', function() { it('should not resolve the browser field for --target=node', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/browser.js', + path.join(__dirname, '/integration/resolve-entries/browser.js'), { target: 'node' } @@ -767,7 +815,7 @@ describe('javascript', function() { it('should resolve advanced browser resolution', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/browser-multiple.js' + path.join(__dirname, '/integration/resolve-entries/browser-multiple.js') ); await assertBundleTree(b, { @@ -794,7 +842,7 @@ describe('javascript', function() { it('should not resolve advanced browser resolution with --target=node', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/browser-multiple.js', + path.join(__dirname, '/integration/resolve-entries/browser-multiple.js'), { target: 'node' } @@ -820,7 +868,7 @@ describe('javascript', function() { it('should resolve the module field before main', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/module-field.js' + path.join(__dirname, '/integration/resolve-entries/module-field.js') ); await assertBundleTree(b, { @@ -841,7 +889,7 @@ describe('javascript', function() { it('should resolve the module field before main', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/both-fields.js' + path.join(__dirname, '/integration/resolve-entries/both-fields.js') ); await assertBundleTree(b, { @@ -862,7 +910,7 @@ describe('javascript', function() { it('should resolve the main field', async function() { let b = await bundle( - __dirname + '/integration/resolve-entries/main-field.js' + path.join(__dirname, '/integration/resolve-entries/main-field.js') ); await assertBundleTree(b, { @@ -882,25 +930,34 @@ describe('javascript', function() { }); it('should minify JSON files', async function() { - await bundle(__dirname + '/integration/uglify-json/index.json', { + await bundle(path.join(__dirname, '/integration/uglify-json/index.json'), { production: true }); - let json = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let json = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(json.includes('{test:"test"}')); }); it('should minify JSON5 files', async function() { - await bundle(__dirname + '/integration/uglify-json5/index.json5', { - production: true - }); + await bundle( + path.join(__dirname, '/integration/uglify-json5/index.json5'), + { + production: true + } + ); - let json = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let json = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(json.includes('{test:"test"}')); }); it('should minify YAML for production', async function() { - let b = await bundle(__dirname + '/integration/yaml/index.js', { + let b = await bundle(path.join(__dirname, '/integration/yaml/index.js'), { scopeHoist: false, production: true }); @@ -909,12 +966,15 @@ describe('javascript', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 3); - let json = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let json = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(json.includes('{a:1,b:{c:2}}')); }); it('should minify TOML for production', async function() { - let b = await bundle(__dirname + '/integration/toml/index.js', { + let b = await bundle(path.join(__dirname, '/integration/toml/index.js'), { scopeHoist: false, production: true }); @@ -923,38 +983,55 @@ describe('javascript', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 3); - let json = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let json = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(json.includes('{a:1,b:{c:2}}')); }); it('should support compiling with babel using .babelrc config', async function() { - await bundle(__dirname + '/integration/babel/index.js'); + await bundle(path.join(__dirname, '/integration/babel/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(!file.includes('function Foo')); assert(!file.includes('function Bar')); }); it('should compile with babel with default engines if no config', async function() { - await bundle(__dirname + '/integration/babel-default/index.js'); + await bundle(path.join(__dirname, '/integration/babel-default/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should support compiling with babel using browserlist', async function() { - await bundle(__dirname + '/integration/babel-browserslist/index.js'); + await bundle( + path.join(__dirname, '/integration/babel-browserslist/index.js') + ); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should support splitting babel-polyfill using browserlist', async function() { - await bundle(__dirname + '/integration/babel-polyfill/index.js'); + await bundle(path.join(__dirname, '/integration/babel-polyfill/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('async function')); assert(!file.includes('regenerator')); }); @@ -967,16 +1044,16 @@ describe('javascript', function() { const devRegExp = /const ?{\s*prop1(:.+)?,\s*prop2(:.+)?,\s*prop3(:.+)?\s*} ?= ?.*/; let file; // Dev build test - await bundle(__dirname + projectBasePath + '/index.js'); - file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + await bundle(path.join(__dirname, projectBasePath, '/index.js')); + file = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(devRegExp.test(file) === true); assert(prodRegExp.test(file) === false); // Prod build test - await bundle(__dirname + projectBasePath + '/index.js', { + await bundle(path.join(__dirname, projectBasePath, '/index.js'), { minify: false, production: true }); - file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + file = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(prodRegExp.test(file) === true); assert(devRegExp.test(file) === false); } @@ -990,88 +1067,145 @@ describe('javascript', function() { }); it('should not compile node_modules by default', async function() { - await bundle(__dirname + '/integration/babel-node-modules/index.js'); + await bundle( + path.join(__dirname, '/integration/babel-node-modules/index.js') + ); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(/class \S+ \{\}/.test(file)); assert(file.includes('function Bar')); }); it('should compile node_modules if legacy browserify options are found', async function() { await bundle( - __dirname + '/integration/babel-node-modules-browserify/index.js' + path.join( + __dirname, + '/integration/babel-node-modules-browserify/index.js' + ) ); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should compile node_modules with browserslist to app target', async function() { await bundle( - __dirname + '/integration/babel-node-modules-browserslist/index.js' + path.join( + __dirname, + '/integration/babel-node-modules-browserslist/index.js' + ) ); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should compile node_modules when symlinked with a source field in package.json', async function() { - await bundle(__dirname + '/integration/babel-node-modules-source/index.js'); + const inputDir = path.join(__dirname, '/input'); + await mkdirp(path.join(inputDir, 'node_modules')); + await ncp( + path.join(path.join(__dirname, '/integration/babel-node-modules-source')), + 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' + ); + + await bundle(inputDir + '/index.js'); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should not compile node_modules with a source field in package.json when not symlinked', async function() { await bundle( - __dirname + '/integration/babel-node-modules-source-unlinked/index.js' + path.join( + __dirname, + '/integration/babel-node-modules-source-unlinked/index.js' + ) ); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(!file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should support compiling JSX', async function() { - await bundle(__dirname + '/integration/jsx/index.jsx'); + await bundle(path.join(__dirname, '/integration/jsx/index.jsx')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('React.createElement("div"')); }); it('should support compiling JSX in JS files with React dependency', async function() { - await bundle(__dirname + '/integration/jsx-react/index.js'); + await bundle(path.join(__dirname, '/integration/jsx-react/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('React.createElement("div"')); }); it('should support compiling JSX in JS files with Preact dependency', async function() { - await bundle(__dirname + '/integration/jsx-preact/index.js'); + await bundle(path.join(__dirname, '/integration/jsx-preact/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('h("div"')); }); it('should support compiling JSX in JS files with Nerv dependency', async function() { - await bundle(__dirname + '/integration/jsx-nervjs/index.js'); + await bundle(path.join(__dirname, '/integration/jsx-nervjs/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('Nerv.createElement("div"')); }); it('should support compiling JSX in JS files with Hyperapp dependency', async function() { - await bundle(__dirname + '/integration/jsx-hyperapp/index.js'); + await bundle(path.join(__dirname, '/integration/jsx-hyperapp/index.js')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('h("div"')); }); it('should support optional dependencies in try...catch blocks', async function() { - let b = await bundle(__dirname + '/integration/optional-dep/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/optional-dep/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -1092,7 +1226,9 @@ describe('javascript', function() { }); it('should support excluding dependencies in falsy branches', async function() { - let b = await bundle(__dirname + '/integration/falsy-dep/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/falsy-dep/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -1112,7 +1248,10 @@ describe('javascript', function() { let error; try { await bundle( - __dirname + '/integration/dont-autoinstall-resolve-fails/index.js' + path.join( + __dirname, + '/integration/dont-autoinstall-resolve-fails/index.js' + ) ); } catch (err) { error = err; @@ -1128,7 +1267,10 @@ describe('javascript', function() { let error; try { await bundle( - __dirname + '/integration/dont-autoinstall-resolve-alias-fails/index.js' + path.join( + __dirname, + '/integration/dont-autoinstall-resolve-alias-fails/index.js' + ) ); } catch (err) { error = err; @@ -1141,7 +1283,9 @@ describe('javascript', function() { }); it('should ignore require if it is defined in the scope', async function() { - let b = await bundle(__dirname + '/integration/require-scope/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/require-scope/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -1165,7 +1309,9 @@ describe('javascript', function() { }); it('should expose to CommonJS entry point', async function() { - let b = await bundle(__dirname + '/integration/entry-point/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/entry-point/index.js') + ); let module = {}; await run(b, {module, exports: {}}); @@ -1173,7 +1319,9 @@ describe('javascript', function() { }); it('should expose to RequireJS entry point', async function() { - let b = await bundle(__dirname + '/integration/entry-point/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/entry-point/index.js') + ); let test; const mockDefine = function(f) { test = f(); @@ -1185,16 +1333,21 @@ describe('javascript', function() { }); it('should expose variable with --browser-global', async function() { - let b = await bundle(__dirname + '/integration/entry-point/index.js', { - global: 'testing' - }); + let b = await bundle( + path.join(__dirname, '/integration/entry-point/index.js'), + { + global: 'testing' + } + ); const ctx = await run(b, {module: undefined}, {require: false}); assert.equal(ctx.window.testing(), 'Test!'); }); it('should set `define` to undefined so AMD checks in UMD modules do not pass', async function() { - let b = await bundle(__dirname + '/integration/define-amd/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/define-amd/index.js') + ); let test; const mockDefine = function(f) { test = f(); @@ -1207,7 +1360,7 @@ describe('javascript', function() { it('should not dedupe imports with different contents', async function() { let b = await bundle( - __dirname + `/integration/js-different-contents/index.js`, + path.join(__dirname, `/integration/js-different-contents/index.js`), { hmr: false // enable asset dedupe in JSPackager } @@ -1219,8 +1372,10 @@ describe('javascript', function() { it('should not dedupe imports with same content but different absolute dependency paths', async function() { let b = await bundle( - __dirname + - `/integration/js-same-contents-different-dependencies/index.js`, + path.join( + __dirname, + `/integration/js-same-contents-different-dependencies/index.js` + ), { hmr: false // enable asset dedupe in JSPackager } @@ -1232,7 +1387,10 @@ describe('javascript', function() { it('should dedupe imports with same content and same dependency paths', async function() { let b = await bundle( - __dirname + `/integration/js-same-contents-same-dependencies/index.js`, + path.join( + __dirname, + `/integration/js-same-contents-same-dependencies/index.js` + ), { hmr: false // enable asset dedupe in JSPackager } @@ -1258,7 +1416,7 @@ describe('javascript', function() { it('should support importing HTML from JS async', async function() { let b = await bundle( - __dirname + '/integration/import-html-async/index.js', + path.join(__dirname, '/integration/import-html-async/index.js'), {sourceMaps: false} ); @@ -1298,7 +1456,7 @@ describe('javascript', function() { it('should support importing HTML from JS async with --target=node', async function() { let b = await bundle( - __dirname + '/integration/import-html-async/index.js', + path.join(__dirname, '/integration/import-html-async/index.js'), { target: 'node', sourceMaps: false @@ -1340,9 +1498,12 @@ describe('javascript', function() { }); it('should support importing HTML from JS sync', async function() { - let b = await bundle(__dirname + '/integration/import-html-sync/index.js', { - sourceMaps: false - }); + let b = await bundle( + path.join(__dirname, '/integration/import-html-sync/index.js'), + { + sourceMaps: false + } + ); await assertBundleTree(b, { name: 'index.js', @@ -1382,20 +1543,23 @@ describe('javascript', function() { it('should strip away flow types of node modules', async function() { let b = await bundle( - __dirname + '/integration/babel-strip-flow-types/index.js' + path.join(__dirname, '/integration/babel-strip-flow-types/index.js') ); let output = await run(b); assert.equal(typeof output, 'function'); assert.equal(output(), 'hello world'); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(!file.includes('OptionsType')); }); it('should stub require.cache', async function() { let b = await bundle( - __dirname + '/integration/node_require_cache/main.js', + path.join(__dirname, '/integration/node_require_cache/main.js'), { target: 'node' } diff --git a/test/less.js b/test/less.js index 7bd170cd89b..01d9c880504 100644 --- a/test/less.js +++ b/test/less.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, run, assertBundleTree} = require('./utils'); describe('less', function() { it('should support requiring less files', async function() { - let b = await bundle(__dirname + '/integration/less/index.js'); + let b = await bundle(path.join(__dirname, '/integration/less/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -25,12 +26,17 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); }); it('should support less imports', async function() { - let b = await bundle(__dirname + '/integration/less-import/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/less-import/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -51,14 +57,17 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); assert(css.includes('.base')); }); it('should support advanced less imports', async function() { let b = await bundle( - __dirname + '/integration/less-advanced-import/index.js' + path.join(__dirname, '/integration/less-advanced-import/index.js') ); await assertBundleTree(b, { @@ -80,13 +89,18 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); assert(css.includes('.base')); }); it('should support requiring empty less files', async function() { - let b = await bundle(__dirname + '/integration/less-empty/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/less-empty/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -107,12 +121,17 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert.equal(css, ''); }); it('should support linking to assets with url() from less', async function() { - let b = await bundle(__dirname + '/integration/less-url/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/less-url/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -138,20 +157,29 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(/url\("test\.[0-9a-f]+\.woff2"\)/.test(css)); assert(css.includes('url("http://google.com")')); assert(css.includes('.index')); assert( await fs.exists( - __dirname + '/dist/' + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + path.join( + __dirname, + '/dist/', + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + ) ) ); }); it('should support transforming less with postcss', async function() { - let b = await bundle(__dirname + '/integration/less-postcss/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/less-postcss/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -172,7 +200,10 @@ describe('less', function() { assert.equal(typeof output, 'function'); assert.equal(output(), '_index_ku5n8_1'); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('._index_ku5n8_1')); }); }); diff --git a/test/parser.js b/test/parser.js index 7d5ab3b6766..0b82acfa26b 100644 --- a/test/parser.js +++ b/test/parser.js @@ -1,11 +1,15 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, assertBundleTree} = require('./utils'); describe('parser', function() { it('should support case-insensitive file extension', async function() { let b = await bundle( - __dirname + '/integration/parser-case-insensitive-ext/index.html' + path.join( + __dirname, + '/integration/parser-case-insensitive-ext/index.html' + ) ); await assertBundleTree(b, { @@ -40,8 +44,8 @@ describe('parser', function() { ] }); - let files = await fs.readdir(__dirname + '/dist'); - let html = await fs.readFile(__dirname + '/dist/index.html'); + let files = await fs.readdir(path.join(__dirname, '/dist')); + let html = await fs.readFile(path.join(__dirname, '/dist/index.html')); for (let file of files) { let ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0]; if (file !== 'index.html' && ext !== '.map') { diff --git a/test/plugins.js b/test/plugins.js index 76ede040b4c..c1510d8200f 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -1,9 +1,10 @@ const assert = require('assert'); +const path = require('path'); const {bundle, run, assertBundleTree} = require('./utils'); describe('plugins', function() { it('should load plugins and apply custom asset type', async function() { - let b = await bundle(__dirname + '/integration/plugins/index.js'); + let b = await bundle(path.join(__dirname, '/integration/plugins/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -21,7 +22,7 @@ describe('plugins', function() { it('should load package.json from parent tree', async function() { let b = await bundle( - __dirname + '/integration/plugins/sub-folder/index.js' + path.join(__dirname, '/integration/plugins/sub-folder/index.js') ); await assertBundleTree(b, { diff --git a/test/pug.js b/test/pug.js index 49cfdb8ad49..c35ebcddd7e 100644 --- a/test/pug.js +++ b/test/pug.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); -const {bundle, assertBundleTree} = require('./utils'); +const {bundle, assertBundleTree, normaliseNewlines} = require('./utils'); describe('pug', function() { it('should support bundling HTML', async function() { - const b = await bundle(__dirname + '/integration/pug/index.pug'); + const b = await bundle(path.join(__dirname, '/integration/pug/index.pug')); await assertBundleTree(b, { name: 'index.html', @@ -37,8 +38,8 @@ describe('pug', function() { ] }); - const files = await fs.readdir(__dirname + '/dist'); - const html = await fs.readFile(__dirname + '/dist/index.html'); + const files = await fs.readdir(path.join(__dirname, '/dist')); + const html = await fs.readFile(path.join(__dirname, '/dist/index.html')); for (const file of files) { const ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0]; if (file !== 'index.html' && ext !== '.map') { @@ -49,7 +50,7 @@ describe('pug', function() { it('should support include and extends files', async function() { const b = await bundle( - __dirname + '/integration/pug-include-extends/index.pug' + path.join(__dirname, '/integration/pug-include-extends/index.pug') ); await assertBundleTree(b, { @@ -57,63 +58,88 @@ describe('pug', function() { assets: ['index.pug'] }); - const html = await fs.readFile(__dirname + '/dist/index.html', 'utf-8'); - const expect = await fs.readFile( - __dirname + '/integration/pug-include-extends/expect.html', - 'utf-8' + const html = normaliseNewlines( + await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf-8') + ); + const expect = normaliseNewlines( + await fs.readFile( + path.join(__dirname, '/integration/pug-include-extends/expect.html'), + 'utf-8' + ) ); assert.equal(html, expect, 'Content mismatch'); }); it('should support variables', async function() { - const b = await bundle(__dirname + '/integration/pug-var/index.pug'); + const b = await bundle( + path.join(__dirname, '/integration/pug-var/index.pug') + ); await assertBundleTree(b, { name: 'index.html', assets: ['index.pug'] }); - const html = await fs.readFile(__dirname + '/dist/index.html', 'utf-8'); + const html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf-8' + ); assert(/src="\/?100x100.*.png"/.test(html)); }); it('should support mixins', async function() { - const b = await bundle(__dirname + '/integration/pug-mixins/index.pug'); + const b = await bundle( + path.join(__dirname, '/integration/pug-mixins/index.pug') + ); await assertBundleTree(b, { name: 'index.html', assets: ['index.pug'] }); - const html = await fs.readFile(__dirname + '/dist/index.html', 'utf-8'); + const html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf-8' + ); assert(html.includes('Greetings, Parcel')); }); it('should support filters', async function() { - const b = await bundle(__dirname + '/integration/pug-filters/index.pug'); + const b = await bundle( + path.join(__dirname, '/integration/pug-filters/index.pug') + ); await assertBundleTree(b, { name: 'index.html', assets: ['index.pug'] }); - const html = await fs.readFile(__dirname + '/dist/index.html', 'utf-8'); + const html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf-8' + ); assert(html.includes('FILTERED: Hello!')); }); it('should minify HTML in production mode', async function() { - const b = await bundle(__dirname + '/integration/pug-minify/index.pug', { - production: true - }); + const b = await bundle( + path.join(__dirname, '/integration/pug-minify/index.pug'), + { + production: true + } + ); await assertBundleTree(b, { name: 'index.html', assets: ['index.pug'] }); - const html = await fs.readFile(__dirname + '/dist/index.html', 'utf-8'); + const html = await fs.readFile( + path.join(__dirname, '/dist/index.html'), + 'utf-8' + ); assert(html.includes('Minified')); }); diff --git a/test/reason.js b/test/reason.js index b6a0e944093..6356858d7ea 100644 --- a/test/reason.js +++ b/test/reason.js @@ -1,9 +1,10 @@ const assert = require('assert'); +const path = require('path'); const {bundle, run} = require('./utils'); describe('reason', function() { it('should produce a bundle', async function() { - let b = await bundle(__dirname + '/integration/reason/index.js'); + let b = await bundle(path.join(__dirname, '/integration/reason/index.js')); assert.equal(b.assets.size, 2); assert.equal(b.childBundles.size, 1); diff --git a/test/resolver.js b/test/resolver.js index ff440a0bf89..33c6483e449 100644 --- a/test/resolver.js +++ b/test/resolver.js @@ -1,17 +1,45 @@ const Resolver = require('../src/Resolver'); const path = require('path'); const assert = require('assert'); +const {rimraf, ncp} = require('./utils'); +const {mkdirp} = require('../src/utils/fs'); +const {symlinkSync} = require('fs'); -const rootDir = path.join(__dirname, 'integration', 'resolver'); -const resolver = new Resolver({ - rootDir, - extensions: { - '.js': true, - '.json': true - } -}); +const rootDir = path.join(__dirname, 'input/resolver'); describe('resolver', function() { + let resolver; + 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' + ); + + resolver = new Resolver({ + rootDir, + extensions: { + '.js': true, + '.json': true + } + }); + }); + describe('file paths', function() { it('should resolve a relative path with an extension', async function() { let resolved = await resolver.resolve( diff --git a/test/rust.js b/test/rust.js index d96163d0419..5467db33fcf 100644 --- a/test/rust.js +++ b/test/rust.js @@ -1,4 +1,5 @@ const assert = require('assert'); +const path = require('path'); const {bundle, bundler, run, assertBundleTree} = require('./utils'); const fs = require('../src/utils/fs'); const commandExists = require('command-exists'); @@ -14,7 +15,7 @@ describe('rust', function() { it('should generate a wasm file from a rust file with rustc with --target=browser', async function() { this.timeout(500000); - let b = await bundle(__dirname + '/integration/rust/index.js'); + let b = await bundle(path.join(__dirname, '/integration/rust/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -45,7 +46,7 @@ describe('rust', function() { it('should generate a wasm file from a rust file with rustc with --target=node', async function() { this.timeout(500000); - let b = await bundle(__dirname + '/integration/rust/index.js', { + let b = await bundle(path.join(__dirname, '/integration/rust/index.js'), { target: 'node' }); @@ -78,7 +79,7 @@ describe('rust', function() { it('should support rust files with dependencies via rustc', async function() { this.timeout(500000); - let b = bundler(__dirname + '/integration/rust-deps/index.js'); + let b = bundler(path.join(__dirname, '/integration/rust-deps/index.js')); let bundle = await b.bundle(); await assertBundleTree(bundle, { @@ -107,7 +108,9 @@ describe('rust', function() { it('should generate a wasm file from a rust file with cargo', async function() { this.timeout(500000); - let b = await bundle(__dirname + '/integration/rust-cargo/src/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/rust-cargo/src/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -136,7 +139,10 @@ describe('rust', function() { it('should generate a wasm file from a rust file in cargo workspace', async function() { this.timeout(500000); let b = await bundle( - __dirname + '/integration/rust-cargo-workspace/member/src/index.js' + path.join( + __dirname, + '/integration/rust-cargo-workspace/member/src/index.js' + ) ); await assertBundleTree(b, { @@ -168,16 +174,19 @@ describe('rust', function() { // Store the size of not minified bundle in order to test it against // the size of minified one. - let b = await bundle(__dirname + '/integration/rust/index.js', { + let b = await bundle(path.join(__dirname, '/integration/rust/index.js'), { minify: false, sourceMaps: false }); const size = (await fs.stat(Array.from(b.childBundles)[0].name)).size; - let bMinified = await bundle(__dirname + '/integration/rust/index.js', { - minify: true, - sourceMaps: false - }); + let bMinified = await bundle( + path.join(__dirname, '/integration/rust/index.js'), + { + minify: true, + sourceMaps: false + } + ); const bundleTree = { name: 'index.js', diff --git a/test/sass.js b/test/sass.js index 3e76ed18754..fdcafa2c7fd 100644 --- a/test/sass.js +++ b/test/sass.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, run, assertBundleTree} = require('./utils'); describe('sass', function() { it('should support requiring sass files', async function() { - let b = await bundle(__dirname + '/integration/sass/index.js'); + let b = await bundle(path.join(__dirname, '/integration/sass/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -25,12 +26,15 @@ describe('sass', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); }); it('should support requiring scss files', async function() { - let b = await bundle(__dirname + '/integration/scss/index.js'); + let b = await bundle(path.join(__dirname, '/integration/scss/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -51,12 +55,17 @@ describe('sass', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); }); it('should support scss imports', async function() { - let b = await bundle(__dirname + '/integration/scss-import/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/scss-import/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -77,14 +86,19 @@ describe('sass', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); assert(css.includes('.foo')); assert(css.includes('.bar')); }); it('should support requiring empty scss files', async function() { - let b = await bundle(__dirname + '/integration/scss-empty/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/scss-empty/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -105,12 +119,17 @@ describe('sass', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert.equal(css, ''); }); it('should support linking to assets with url() from scss', async function() { - let b = await bundle(__dirname + '/integration/scss-url/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/scss-url/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -141,20 +160,29 @@ describe('sass', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(/url\("test\.[0-9a-f]+\.woff2"\)/.test(css)); assert(css.includes('url("http://google.com")')); assert(css.includes('.index')); assert( await fs.exists( - __dirname + '/dist/' + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + path.join( + __dirname, + '/dist/', + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + ) ) ); }); it('should support transforming scss with postcss', async function() { - let b = await bundle(__dirname + '/integration/scss-postcss/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/scss-postcss/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -176,13 +204,16 @@ describe('sass', function() { let className = output(); assert.notStrictEqual(className, 'index'); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes(`.${className}`)); }); it('should support advanced import syntax', async function() { let b = await bundle( - __dirname + '/integration/sass-advanced-import/index.sass' + path.join(__dirname, '/integration/sass-advanced-import/index.sass') ); await assertBundleTree(b, { @@ -191,7 +222,7 @@ describe('sass', function() { }); let css = (await fs.readFile( - __dirname + '/dist/index.css', + path.join(__dirname, '/dist/index.css'), 'utf8' )).replace(/\s+/g, ' '); assert(css.includes('.foo { color: blue;')); diff --git a/test/scope-hoisting.js b/test/scope-hoisting.js index d7c6b323cfc..ebf2a765a6d 100644 --- a/test/scope-hoisting.js +++ b/test/scope-hoisting.js @@ -1,4 +1,5 @@ const assert = require('assert'); +const path = require('path'); const {bundle: _bundle, run} = require('./utils'); const fs = require('../src/utils/fs'); @@ -6,11 +7,22 @@ const bundle = (name, opts = {}) => _bundle(name, Object.assign({scopeHoist: true}, opts)); describe('scope hoisting', function() { + if (process.platform === 'win32') { + // eslint-disable-next-line no-console + console.warn( + 'WARNING: Scope hoisting tests are disabled on windows due to ' + + 'filesystem errors. Feel free to look into this and contribute a fix!' + ); + return; + } + describe('es6', function() { it('supports default imports and exports of expressions', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/default-export-expression/a.js' + ) ); let output = await run(b); @@ -19,8 +31,10 @@ describe('scope hoisting', function() { it('supports default imports and exports of declarations', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/default-export-declaration/a.js' + ) ); let output = await run(b); @@ -29,8 +43,10 @@ describe('scope hoisting', function() { it('supports default imports and exports of anonymous declarations', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/default-export-anonymous/a.js' + ) ); let output = await run(b); @@ -39,8 +55,10 @@ describe('scope hoisting', function() { it('supports default imports and exports of variables', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/default-export-variable/a.js' + ) ); let output = await run(b); @@ -49,8 +67,10 @@ describe('scope hoisting', function() { it('supports named imports and exports of declarations', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/named-export-declaration/a.js' + ) ); let output = await run(b); @@ -59,7 +79,10 @@ describe('scope hoisting', function() { it('supports named imports and exports of variables', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/named-export-variable/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/named-export-variable/a.js' + ) ); let output = await run(b); @@ -68,7 +91,10 @@ describe('scope hoisting', function() { it('supports renaming imports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/renamed-import/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/renamed-import/a.js' + ) ); let output = await run(b); @@ -77,7 +103,10 @@ describe('scope hoisting', function() { it('supports renaming exports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/renamed-export/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/renamed-export/a.js' + ) ); let output = await run(b); @@ -86,7 +115,10 @@ describe('scope hoisting', function() { it('supports importing a namespace of exported values', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/import-namespace/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/import-namespace/a.js' + ) ); let output = await run(b); @@ -95,7 +127,10 @@ describe('scope hoisting', function() { it('supports re-exporting all exports from another module', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-all/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-all/a.js' + ) ); let output = await run(b); @@ -104,8 +139,10 @@ describe('scope hoisting', function() { it('supports re-exporting all exports from multiple modules', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/re-export-all-multiple/a.js' + ) ); let output = await run(b); @@ -114,8 +151,10 @@ describe('scope hoisting', function() { it('supports importing all exports re-exported from multiple modules deep', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/import-multiple-wildcards/a.js' + ) ); let {foo, bar, baz, a, b: bb} = await run(b); @@ -124,7 +163,10 @@ describe('scope hoisting', function() { it('supports re-exporting all exports from multiple modules deep', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-multiple/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-multiple/a.js' + ) ); let output = await run(b); @@ -133,7 +175,10 @@ describe('scope hoisting', function() { it('supports re-exporting individual named exports from another module', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-named/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-named/a.js' + ) ); let output = await run(b); @@ -142,7 +187,10 @@ describe('scope hoisting', function() { it('supports re-exporting default exports from another module', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-default/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-default/a.js' + ) ); let output = await run(b); @@ -151,7 +199,10 @@ describe('scope hoisting', function() { it('supports re-exporting a namespace from another module', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-namespace/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-namespace/a.js' + ) ); let output = await run(b); @@ -162,8 +213,10 @@ describe('scope hoisting', function() { let threw = false; try { await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/re-export-exclude-default/a.js' + ) ); } catch (err) { threw = true; @@ -175,7 +228,10 @@ describe('scope hoisting', function() { it('supports multiple exports of the same variable', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/multi-export/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/multi-export/a.js' + ) ); let output = await run(b); @@ -184,7 +240,10 @@ describe('scope hoisting', function() { it('supports live bindings of named exports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/live-bindings/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/live-bindings/a.js' + ) ); let output = await run(b); @@ -193,7 +252,10 @@ describe('scope hoisting', function() { it('supports dynamic import syntax for code splitting', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/dynamic-import/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/dynamic-import/a.js' + ) ); let output = await run(b); @@ -202,8 +264,10 @@ describe('scope hoisting', function() { it('should not export function arguments', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/export-binding-identifiers/a.js' + ) ); let output = await run(b); @@ -212,8 +276,10 @@ describe('scope hoisting', function() { it('supports import default CommonJS interop', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/import-commonjs-default/a.js' + ) ); let output = await run(b); @@ -222,8 +288,10 @@ describe('scope hoisting', function() { it('supports import default CommonJS interop with dynamic imports', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/dynamic-default-interop/a.js' + ) ); let output = await run(b); @@ -232,7 +300,10 @@ describe('scope hoisting', function() { it('supports exporting an import', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-var/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-var/a.js' + ) ); let output = await run(b); @@ -241,7 +312,10 @@ describe('scope hoisting', function() { it('keeps side effects by default', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/side-effects/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/side-effects/a.js' + ) ); let called = false; @@ -257,7 +331,10 @@ describe('scope hoisting', function() { it('supports the package.json sideEffects: false flag', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/side-effects-false/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/side-effects-false/a.js' + ) ); let called = false; @@ -273,8 +350,10 @@ describe('scope hoisting', function() { it('supports wildcards with sideEffects: false', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/side-effects-false-wildcards/a.js' + ) ); let output = await run(b); @@ -283,7 +362,10 @@ describe('scope hoisting', function() { it('supports the package.json sideEffects flag with an array', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/side-effects-array/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/side-effects-array/a.js' + ) ); let calls = []; @@ -299,7 +381,10 @@ describe('scope hoisting', function() { it('missing exports should be replaced with an empty object', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/empty-module/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/empty-module/a.js' + ) ); let output = await run(b); @@ -308,8 +393,10 @@ describe('scope hoisting', function() { it('supports importing a namespace from a commonjs module when code split', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/es6/import-namespace-commonjs/a.js' + ) ); let output = await run(b); @@ -318,20 +405,29 @@ describe('scope hoisting', function() { it('removes unused exports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/tree-shaking/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/tree-shaking/a.js' + ) ); let output = await run(b); assert.deepEqual(output.default, 2); - let contents = await fs.readFile(__dirname + '/dist/a.js', 'utf8'); + let contents = await fs.readFile( + path.join(__dirname, '/dist/a.js'), + 'utf8' + ); assert(contents.includes('foo')); assert(!contents.includes('bar')); }); it('support exporting a ES6 module exported as CommonJS', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/re-export-commonjs/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/re-export-commonjs/a.js' + ) ); let output = await run(b); @@ -340,7 +436,10 @@ describe('scope hoisting', function() { it('should support named imports on wrapped modules', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/import-wrapped/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/es6/import-wrapped/a.js' + ) ); let output = await run(b); @@ -349,7 +448,7 @@ describe('scope hoisting', function() { it('should not nameclash with internal variables', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/es6/name-clash/a.js' + path.join(__dirname, '/integration/scope-hoisting/es6/name-clash/a.js') ); let output = await run(b); @@ -360,7 +459,10 @@ describe('scope hoisting', function() { describe('commonjs', function() { it('supports require of commonjs modules', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/require/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/require/a.js' + ) ); let output = await run(b); @@ -369,7 +471,10 @@ describe('scope hoisting', function() { it('supports default imports of commonjs modules', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/default-import/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/default-import/a.js' + ) ); let output = await run(b); @@ -378,7 +483,10 @@ describe('scope hoisting', function() { it('supports named imports of commonjs modules', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/named-import/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/named-import/a.js' + ) ); let output = await run(b); @@ -387,7 +495,10 @@ describe('scope hoisting', function() { it('supports namespace imports of commonjs modules', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/import-namespace/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/import-namespace/a.js' + ) ); let output = await run(b); @@ -396,8 +507,10 @@ describe('scope hoisting', function() { it('supports require of es6 default export of expressions', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-default-export-expression/a.js' + ) ); let output = await run(b); @@ -406,8 +519,10 @@ describe('scope hoisting', function() { it('supports require of es6 default export of declarations', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-default-export-declaration/a.js' + ) ); let output = await run(b); @@ -416,8 +531,10 @@ describe('scope hoisting', function() { it('supports require of es6 default export of variables', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-default-export-variable/a.js' + ) ); let output = await run(b); @@ -426,8 +543,10 @@ describe('scope hoisting', function() { it('supports require of es6 named export of declarations', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-named-export-declaration/a.js' + ) ); let output = await run(b); @@ -436,8 +555,10 @@ describe('scope hoisting', function() { it('supports require of es6 named export of variables', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-named-export-variable/a.js' + ) ); let output = await run(b); @@ -446,8 +567,10 @@ describe('scope hoisting', function() { it('supports require of es6 renamed exports', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-renamed-export/a.js' + ) ); let output = await run(b); @@ -456,8 +579,10 @@ describe('scope hoisting', function() { it('supports require of es6 module re-exporting all exports from another module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-all/a.js' + ) ); let output = await run(b); @@ -466,8 +591,10 @@ describe('scope hoisting', function() { it('supports require of es6 module re-exporting all exports from multiple modules', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-multiple/a.js' + ) ); let output = await run(b); @@ -476,8 +603,10 @@ describe('scope hoisting', function() { it('supports re-exporting individual named exports from another module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-named/a.js' + ) ); let output = await run(b); @@ -486,8 +615,10 @@ describe('scope hoisting', function() { it('supports re-exporting default exports from another module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-default/a.js' + ) ); let output = await run(b); @@ -496,8 +627,10 @@ describe('scope hoisting', function() { it('supports re-exporting a namespace from another module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-namespace/a.js' + ) ); let output = await run(b); @@ -506,8 +639,10 @@ describe('scope hoisting', function() { it('excludes default when re-exporting a module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-re-export-exclude-default/a.js' + ) ); let output = await run(b); @@ -516,8 +651,10 @@ describe('scope hoisting', function() { it('supports hybrid ES6 + commonjs modules', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/es6-commonjs-hybrid/a.js' + ) ); let output = await run(b); @@ -526,7 +663,10 @@ describe('scope hoisting', function() { it('inserts commonjs exports object in the right place', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/export-order/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/export-order/a.js' + ) ); let output = await run(b); @@ -535,7 +675,10 @@ describe('scope hoisting', function() { it('define exports in the outermost scope', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/define-exports/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/define-exports/a.js' + ) ); let output = await run(b); @@ -544,7 +687,10 @@ describe('scope hoisting', function() { it('supports live bindings of named exports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/live-bindings/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/live-bindings/a.js' + ) ); let output = await run(b); @@ -553,7 +699,10 @@ describe('scope hoisting', function() { it('should wrap modules that use eval in a function', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/wrap-eval/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/wrap-eval/a.js' + ) ); let output = await run(b); @@ -562,7 +711,10 @@ describe('scope hoisting', function() { it('should wrap modules that have a top-level return', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/wrap-return/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/wrap-return/a.js' + ) ); let output = await run(b); @@ -571,7 +723,10 @@ describe('scope hoisting', function() { it('should wrap modules that access `module` as a free variable', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/wrap-module/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/wrap-module/a.js' + ) ); let output = await run(b); @@ -580,8 +735,10 @@ describe('scope hoisting', function() { it('should wrap modules that non-statically access `module`', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/wrap-module-computed/a.js' + ) ); let output = await run(b); @@ -590,7 +747,10 @@ describe('scope hoisting', function() { it('supports assigning to this as exports object', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/this-reference/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/this-reference/a.js' + ) ); let output = await run(b); @@ -599,8 +759,10 @@ describe('scope hoisting', function() { it('supports assigning to this as exports object in wrapped module', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/this-reference-wrapped/a.js' + ) ); let output = await run(b); @@ -609,7 +771,10 @@ describe('scope hoisting', function() { it('supports module object properties', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/module-object/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/module-object/a.js' + ) ); // TODO: this test doesn't currently work in older browsers since babel @@ -625,7 +790,10 @@ describe('scope hoisting', function() { it('supports require.resolve calls', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/require-resolve/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/require-resolve/a.js' + ) ); let output = await run(b); @@ -637,7 +805,10 @@ describe('scope hoisting', function() { it('supports requiring a re-exported ES6 import', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/re-export-var/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/re-export-var/a.js' + ) ); let output = await run(b); @@ -646,7 +817,10 @@ describe('scope hoisting', function() { it('supports object pattern requires', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/object-pattern/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/object-pattern/a.js' + ) ); let output = await run(b); @@ -655,8 +829,10 @@ describe('scope hoisting', function() { it('eliminates CommonJS export object where possible', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/eliminate-exports/a.js' + ) ); let output = await run(b); @@ -665,7 +841,10 @@ describe('scope hoisting', function() { it('supports multiple assignments in one line', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/multi-assign/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/multi-assign/a.js' + ) ); let output = await run(b); @@ -674,7 +853,10 @@ describe('scope hoisting', function() { it('supports circular dependencies', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/require-circular/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/require-circular/a.js' + ) ); let output = await run(b); @@ -683,8 +865,10 @@ describe('scope hoisting', function() { it('executes modules in the correct order', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-execution-order/a.js' + ) ); let out = []; @@ -699,8 +883,10 @@ describe('scope hoisting', function() { it('supports conditional requires', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-conditional/a.js' + ) ); let out = []; @@ -726,8 +912,10 @@ describe('scope hoisting', function() { it('supports requires inside functions', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-in-function/a.js' + ) ); let out = []; @@ -742,8 +930,10 @@ describe('scope hoisting', function() { it('supports requires inside functions with es6 import side effects', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-in-function-import/a.js' + ) ); let out = []; @@ -758,8 +948,10 @@ describe('scope hoisting', function() { it('hoists import calls to the top', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-in-function-import-hoist/a.js' + ) ); let out = []; @@ -774,8 +966,10 @@ describe('scope hoisting', function() { it('supports requires inside functions with es6 re-export side effects', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/require-in-function-reexport/a.js' + ) ); let out = []; @@ -790,7 +984,10 @@ describe('scope hoisting', function() { it('can bundle the node stream module', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/stream-module/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/stream-module/a.js' + ) ); let res = await run(b); @@ -801,7 +998,10 @@ describe('scope hoisting', function() { it('missing exports should be replaced with an empty object', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/empty-module/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/empty-module/a.js' + ) ); let output = await run(b); @@ -810,13 +1010,19 @@ describe('scope hoisting', function() { it('removes unused exports', async function() { let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/tree-shaking/a.js' + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/tree-shaking/a.js' + ) ); let output = await run(b); assert.deepEqual(output, 2); - let contents = await fs.readFile(__dirname + '/dist/a.js', 'utf8'); + let contents = await fs.readFile( + path.join(__dirname, '/dist/a.js'), + 'utf8' + ); assert(contents.includes('foo')); assert(!contents.includes('bar')); }); @@ -825,7 +1031,10 @@ describe('scope hoisting', function() { // Uglify does strange things to multiple assignments in a line. // See https://github.com/parcel-bundler/parcel/issues/1549 let b = await bundle( - __dirname + '/integration/scope-hoisting/commonjs/export-local/a.js', + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/export-local/a.js' + ), {minify: true} ); @@ -835,8 +1044,10 @@ describe('scope hoisting', function() { it('should support sideEffects: false', async function() { let b = await bundle( - __dirname + + path.join( + __dirname, '/integration/scope-hoisting/commonjs/side-effects-false/a.js' + ) ); let output = await run(b); diff --git a/test/server.js b/test/server.js index 53a67c19e53..cff34af0164 100644 --- a/test/server.js +++ b/test/server.js @@ -1,4 +1,5 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundler} = require('./utils'); const http = require('http'); @@ -38,32 +39,35 @@ describe('server', function() { } it('should serve files', async function() { - let b = bundler(__dirname + '/integration/commonjs/index.js'); + let b = bundler(path.join(__dirname, '/integration/commonjs/index.js')); server = await b.serve(0); let data = await get('/index.js'); - assert.equal(data, await fs.readFile(__dirname + '/dist/index.js', 'utf8')); + assert.equal( + data, + await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8') + ); }); it('should serve a default page if the main bundle is an HTML asset', async function() { - let b = bundler(__dirname + '/integration/html/index.html'); + let b = bundler(path.join(__dirname, '/integration/html/index.html')); server = await b.serve(0); let data = await get('/'); assert.equal( data, - await fs.readFile(__dirname + '/dist/index.html', 'utf8') + await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8') ); data = await get('/foo/bar'); assert.equal( data, - await fs.readFile(__dirname + '/dist/index.html', 'utf8') + await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8') ); }); it('should serve a 404 if the file does not exist', async function() { - let b = bundler(__dirname + '/integration/commonjs/index.js'); + let b = bundler(path.join(__dirname, '/integration/commonjs/index.js')); server = await b.serve(0); let threw = false; @@ -77,7 +81,7 @@ describe('server', function() { }); it('should serve a 500 if the bundler errored', async function() { - let b = bundler(__dirname + '/integration/html/index.html'); + let b = bundler(path.join(__dirname, '/integration/html/index.html')); server = await b.serve(0); b.errored = true; @@ -94,7 +98,7 @@ describe('server', function() { it('should serve a 500 response with error stack trace when bundler has errors', async function() { let b = bundler( - __dirname + '/integration/bundler-error-syntax-error/index.html' + path.join(__dirname, '/integration/bundler-error-syntax-error/index.html') ); server = await b.serve(0); @@ -118,7 +122,7 @@ describe('server', function() { let NODE_ENV = process.env.NODE_ENV; process.env.NODE_ENV = 'production'; let b = bundler( - __dirname + '/integration/bundler-error-syntax-error/index.html' + path.join(__dirname, '/integration/bundler-error-syntax-error/index.html') ); server = await b.serve(0); @@ -144,36 +148,45 @@ describe('server', function() { }); it('should support HTTPS', async function() { - let b = bundler(__dirname + '/integration/commonjs/index.js'); + let b = bundler(path.join(__dirname, '/integration/commonjs/index.js')); server = await b.serve(0, true); let data = await get('/index.js', https); - assert.equal(data, await fs.readFile(__dirname + '/dist/index.js', 'utf8')); + assert.equal( + data, + await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8') + ); }); it('should support HTTPS via custom certificate', async function() { - let b = bundler(__dirname + '/integration/commonjs/index.js'); + let b = bundler(path.join(__dirname, '/integration/commonjs/index.js')); server = await b.serve(0, { - key: __dirname + '/integration/https/private.pem', - cert: __dirname + '/integration/https/primary.crt' + key: path.join(__dirname, '/integration/https/private.pem'), + cert: path.join(__dirname, '/integration/https/primary.crt') }); let data = await get('/index.js', https); - assert.equal(data, await fs.readFile(__dirname + '/dist/index.js', 'utf8')); + assert.equal( + data, + await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8') + ); }); it('should support setting a public url', async function() { - let b = bundler(__dirname + '/integration/commonjs/index.js', { + let b = bundler(path.join(__dirname, '/integration/commonjs/index.js'), { publicUrl: '/dist' }); server = await b.serve(0); let data = await get('/dist/index.js'); - assert.equal(data, await fs.readFile(__dirname + '/dist/index.js', 'utf8')); + assert.equal( + data, + await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8') + ); }); it('should serve static assets as well as html', async function() { - let b = bundler(__dirname + '/integration/html/index.html', { + let b = bundler(path.join(__dirname, '/integration/html/index.html'), { publicUrl: '/' }); server = await b.serve(0); @@ -181,16 +194,16 @@ describe('server', function() { let data = await get('/'); assert.equal( data, - await fs.readFile(__dirname + '/dist/index.html', 'utf8') + await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8') ); // When accessing /hello.txt we should get txt document. - await fs.writeFile(__dirname + '/dist/hello.txt', 'hello'); + await fs.writeFile(path.join(__dirname, '/dist/hello.txt'), 'hello'); data = await get('/hello.txt'); assert.equal(data, 'hello'); }); it('should work with query parameters that contain a dot', async function() { - let b = bundler(__dirname + '/integration/html/index.html', { + let b = bundler(path.join(__dirname, '/integration/html/index.html'), { publicUrl: '/' }); server = await b.serve(0); @@ -198,7 +211,7 @@ describe('server', function() { let data = await get('/?foo=bar.baz'); assert.equal( data, - await fs.readFile(__dirname + '/dist/index.html', 'utf8') + await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8') ); }); }); diff --git a/test/sourcemaps.js b/test/sourcemaps.js index be8b1223ad0..598343a52ce 100644 --- a/test/sourcemaps.js +++ b/test/sourcemaps.js @@ -6,7 +6,7 @@ const {bundler, bundle, run, assertBundleTree} = require('./utils'); describe('sourcemaps', function() { it('should create a valid sourcemap as a child of a JS bundle', async function() { - let b = bundler(__dirname + '/integration/sourcemap/index.js'); + let b = bundler(path.join(__dirname, '/integration/sourcemap/index.js')); let bu = await b.bundle(); await assertBundleTree(bu, { @@ -51,7 +51,7 @@ describe('sourcemaps', function() { it('should create a valid sourcemap as a child of a TS bundle', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-typescript/index.ts' + path.join(__dirname, '/integration/sourcemap-typescript/index.ts') ); await assertBundleTree(b, { @@ -80,7 +80,7 @@ describe('sourcemaps', function() { it('should create a valid sourcemap as a child of a nested TS bundle', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-typescript-nested/index.ts' + path.join(__dirname, '/integration/sourcemap-typescript-nested/index.ts') ); await assertBundleTree(b, { @@ -108,7 +108,9 @@ describe('sourcemaps', function() { }); it('should create a valid sourcemap for a js file with requires', async function() { - let b = await bundle(__dirname + '/integration/sourcemap-nested/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/sourcemap-nested/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -136,7 +138,7 @@ describe('sourcemaps', function() { it('should create a valid sourcemap for a minified js bundle with requires', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-nested-minified/index.js', + path.join(__dirname, '/integration/sourcemap-nested-minified/index.js'), { minify: true } @@ -168,7 +170,7 @@ describe('sourcemaps', function() { it('should create a valid sourcemap reference for a child bundle', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-reference/index.html' + path.join(__dirname, '/integration/sourcemap-reference/index.html') ); await assertBundleTree(b, { @@ -207,7 +209,7 @@ describe('sourcemaps', function() { it('should load existing sourcemaps of libraries', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-existing/index.js' + path.join(__dirname, '/integration/sourcemap-existing/index.js') ); assertBundleTree(b, { @@ -242,7 +244,9 @@ describe('sourcemaps', function() { }); it('should load inline sourcemaps of libraries', async function() { - let b = await bundle(__dirname + '/integration/sourcemap-inline/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/sourcemap-inline/index.js') + ); assertBundleTree(b, { name: 'index.js', @@ -277,7 +281,7 @@ describe('sourcemaps', function() { it('should load referenced contents of sourcemaps', async function() { let b = await bundle( - __dirname + '/integration/sourcemap-external-contents/index.js' + path.join(__dirname, '/integration/sourcemap-external-contents/index.js') ); assertBundleTree(b, { diff --git a/test/stylus.js b/test/stylus.js index 045fb127778..3704be344dc 100644 --- a/test/stylus.js +++ b/test/stylus.js @@ -1,10 +1,11 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, run, assertBundleTree} = require('./utils'); describe('stylus', function() { it('should support requiring stylus files', async function() { - let b = await bundle(__dirname + '/integration/stylus/index.js'); + let b = await bundle(path.join(__dirname, '/integration/stylus/index.js')); await assertBundleTree(b, { name: 'index.js', @@ -25,12 +26,17 @@ describe('stylus', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); }); it('should support requiring stylus files with dependencies', async function() { - let b = await bundle(__dirname + '/integration/stylus-deps/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/stylus-deps/index.js') + ); // a.styl shouldn't be included as a dependency that we can see. // stylus takes care of inlining it. @@ -53,7 +59,10 @@ describe('stylus', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); assert(css.includes('.a')); assert(css.includes('-webkit-box')); @@ -61,7 +70,9 @@ describe('stylus', function() { }); it('should support linking to assets with url() from stylus', async function() { - let b = await bundle(__dirname + '/integration/stylus-url/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/stylus-url/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -87,20 +98,29 @@ describe('stylus', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(/url\("test\.[0-9a-f]+\.woff2"\)/.test(css)); assert(css.includes('url("http://google.com")')); assert(css.includes('.index')); assert( await fs.exists( - __dirname + '/dist/' + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + path.join( + __dirname, + '/dist/', + css.match(/url\("(test\.[0-9a-f]+\.woff2)"\)/)[1] + ) ) ); }); it('should support transforming stylus with postcss', async function() { - let b = await bundle(__dirname + '/integration/stylus-postcss/index.js'); + let b = await bundle( + path.join(__dirname, '/integration/stylus-postcss/index.js') + ); await assertBundleTree(b, { name: 'index.js', @@ -121,13 +141,16 @@ describe('stylus', function() { assert.equal(typeof output, 'function'); assert.equal(output(), '_index_g9mqo_1'); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('._index_g9mqo_1')); }); it('should support requiring stylus files with glob dependencies', async function() { let b = await bundle( - __dirname + '/integration/stylus-glob-import/index.js' + path.join(__dirname, '/integration/stylus-glob-import/index.js') ); await assertBundleTree(b, { @@ -149,7 +172,10 @@ describe('stylus', function() { assert.equal(typeof output, 'function'); assert.equal(output(), 2); - let css = await fs.readFile(__dirname + '/dist/index.css', 'utf8'); + let css = await fs.readFile( + path.join(__dirname, '/dist/index.css'), + 'utf8' + ); assert(css.includes('.index')); assert(css.includes('.main')); assert(css.includes('.foo')); diff --git a/test/sugarss.js b/test/sugarss.js index 88e5ff33459..bf83487f41d 100644 --- a/test/sugarss.js +++ b/test/sugarss.js @@ -5,7 +5,9 @@ const path = require('path'); describe('sugarss', function() { it('should correctly parse SugarSS asset', async function() { - let b = await bundle(__dirname + '/integration/sugarss/index.sss'); + let b = await bundle( + path.join(__dirname, '/integration/sugarss/index.sss') + ); await assertBundleTree(b, { name: 'index.css', diff --git a/test/typescript.js b/test/typescript.js index ab8520b6c14..e48b154b73c 100644 --- a/test/typescript.js +++ b/test/typescript.js @@ -1,10 +1,13 @@ const assert = require('assert'); +const path = require('path'); const fs = require('../src/utils/fs'); const {bundle, run, assertBundleTree} = require('./utils'); describe('typescript', function() { it('should produce a ts bundle using ES6 imports', async function() { - let b = await bundle(__dirname + '/integration/typescript/index.ts'); + let b = await bundle( + path.join(__dirname, '/integration/typescript/index.ts') + ); assert.equal(b.assets.size, 2); assert.equal(b.childBundles.size, 1); @@ -16,7 +19,7 @@ describe('typescript', function() { it('should produce a ts bundle using commonJS require', async function() { let b = await bundle( - __dirname + '/integration/typescript-require/index.ts' + path.join(__dirname, '/integration/typescript-require/index.ts') ); assert.equal(b.assets.size, 2); @@ -28,7 +31,9 @@ describe('typescript', function() { }); it('should support json require', async function() { - let b = await bundle(__dirname + '/integration/typescript-json/index.ts'); + let b = await bundle( + path.join(__dirname, '/integration/typescript-json/index.ts') + ); assert.equal(b.assets.size, 2); assert.equal(b.childBundles.size, 1); @@ -39,7 +44,9 @@ describe('typescript', function() { }); it('should support env variables', async function() { - let b = await bundle(__dirname + '/integration/typescript-env/index.ts'); + let b = await bundle( + path.join(__dirname, '/integration/typescript-env/index.ts') + ); assert.equal(b.assets.size, 1); assert.equal(b.childBundles.size, 1); @@ -50,7 +57,9 @@ describe('typescript', function() { }); it('should support importing a URL to a raw asset', async function() { - let b = await bundle(__dirname + '/integration/typescript-raw/index.ts'); + let b = await bundle( + path.join(__dirname, '/integration/typescript-raw/index.ts') + ); await assertBundleTree(b, { name: 'index.js', @@ -70,12 +79,12 @@ describe('typescript', function() { let output = await run(b); assert.equal(typeof output.getRaw, 'function'); assert(/^\/test\.[0-9a-f]+\.txt$/.test(output.getRaw())); - assert(await fs.exists(__dirname + '/dist/' + output.getRaw())); + assert(await fs.exists(path.join(__dirname, '/dist/', output.getRaw()))); }); it('should minify in production mode', async function() { let b = await bundle( - __dirname + '/integration/typescript-require/index.ts', + path.join(__dirname, '/integration/typescript-require/index.ts'), {production: true} ); @@ -86,30 +95,35 @@ describe('typescript', function() { assert.equal(typeof output.count, 'function'); assert.equal(output.count(), 3); - let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(!js.includes('local.a')); }); it('should support loading tsconfig.json', async function() { - let b = await bundle(__dirname + '/integration/typescript-config/index.ts'); + let b = await bundle( + path.join(__dirname, '/integration/typescript-config/index.ts') + ); let output = await run(b); assert.equal(output, 2); - let js = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(!js.includes('/* test comment */')); }); it('should support compiling JSX', async function() { - await bundle(__dirname + '/integration/typescript-jsx/index.tsx'); + await bundle(path.join(__dirname, '/integration/typescript-jsx/index.tsx')); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(file.includes('React.createElement("div"')); }); it('should use esModuleInterop by default', async function() { let b = await bundle( - __dirname + '/integration/typescript-interop/index.ts' + path.join(__dirname, '/integration/typescript-interop/index.ts') ); await assertBundleTree(b, { diff --git a/test/utils.js b/test/utils.js index 8e6d70a7614..f43be64b9c1 100644 --- a/test/utils.js +++ b/test/utils.js @@ -11,16 +11,31 @@ const promisify = require('../src/utils/promisify'); const rimraf = promisify(require('rimraf')); const ncp = promisify(require('ncp')); -beforeEach(async function() { - // Test run in a single process, creating and deleting the same file(s) - // Windows needs a delay for the file handles to be released before deleting - // is possible. Without a delay, rimraf fails on `beforeEach` for `/dist` - if (process.platform === 'win32') { - await sleep(50); +const chalk = new (require('chalk')).constructor({enabled: true}); +const warning = chalk.keyword('orange'); +// eslint-disable-next-line no-console +console.warn = (...args) => { + // eslint-disable-next-line no-console + console.error(warning(...args)); +}; + +async function removeDistDirectory(count = 0) { + try { + await rimraf(path.join(__dirname, 'dist')); + } catch (e) { + if (count > 8) { + // eslint-disable-next-line no-console + console.warn('WARNING: Unable to remove dist directory:', e.message); + return; + } + + await sleep(250); + await removeDistDirectory(count + 1); } - // Unix based systems also need a delay but only half as much as windows - await sleep(50); - await rimraf(path.join(__dirname, 'dist')); +} + +beforeEach(async function() { + await removeDistDirectory(); }); function sleep(ms) { @@ -251,6 +266,10 @@ function deferred() { return promise; } +function normaliseNewlines(text) { + return text.replace(/(\r\n|\n|\r)/g, '\n'); +} + exports.sleep = sleep; exports.bundler = bundler; exports.bundle = bundle; @@ -260,3 +279,4 @@ exports.nextBundle = nextBundle; exports.deferred = deferred; exports.rimraf = rimraf; exports.ncp = ncp; +exports.normaliseNewlines = normaliseNewlines; diff --git a/test/vue.js b/test/vue.js index b2f1343ee33..8e19930f8e5 100644 --- a/test/vue.js +++ b/test/vue.js @@ -1,10 +1,13 @@ const assert = require('assert'); +const path = require('path'); const {bundle, assertBundleTree, run} = require('./utils'); const fs = require('../src/utils/fs'); describe('vue', function() { it('should produce a basic vue bundle', async function() { - let b = await bundle(__dirname + '/integration/vue-basic/Basic.vue'); + let b = await bundle( + path.join(__dirname, '/integration/vue-basic/Basic.vue') + ); await assertBundleTree(b, { type: 'js', @@ -27,7 +30,9 @@ describe('vue', function() { }); it('should produce a vue bundle with dependencies', async function() { - let b = await bundle(__dirname + '/integration/vue-dependencies/App.vue'); + let b = await bundle( + path.join(__dirname, '/integration/vue-dependencies/App.vue') + ); await assertBundleTree(b, { type: 'js', @@ -54,7 +59,7 @@ describe('vue', function() { it('should produce a vue bundle using preprocessors', async function() { let b = await bundle( - __dirname + '/integration/vue-preprocessors/pre-processors.vue' + path.join(__dirname, '/integration/vue-preprocessors/pre-processors.vue') ); await assertBundleTree(b, { @@ -76,7 +81,7 @@ describe('vue', function() { assert.deepEqual(output.data(), {msg: 'Hello from coffee!'}); let contents = await fs.readFile( - __dirname + '/dist/pre-processors.css', + path.join(__dirname, '/dist/pre-processors.css'), 'utf8' ); assert(contents.includes('color: #999')); @@ -86,7 +91,7 @@ describe('vue', function() { it('should produce a vue bundle using a functional component', async function() { let b = await bundle( - __dirname + '/integration/vue-functional/functional.vue' + path.join(__dirname, '/integration/vue-functional/functional.vue') ); await assertBundleTree(b, { @@ -110,14 +115,16 @@ describe('vue', function() { assert.equal(typeof ctx.$style.red, 'string'); let contents = await fs.readFile( - __dirname + '/dist/functional.css', + path.join(__dirname, '/dist/functional.css'), 'utf8' ); assert(contents.includes('.' + ctx.$style.red)); }); it('should produce a vue bundle using scoped styles', async function() { - let b = await bundle(__dirname + '/integration/vue-scoped/App.vue'); + let b = await bundle( + path.join(__dirname, '/integration/vue-scoped/App.vue') + ); await assertBundleTree(b, { type: 'js', @@ -138,12 +145,17 @@ describe('vue', function() { assert(/^data-v-[0-9a-h]{6}$/.test(output._scopeId)); assert.deepEqual(output.data(), {ok: true}); - let contents = await fs.readFile(__dirname + '/dist/App.css', 'utf8'); + let contents = await fs.readFile( + path.join(__dirname, '/dist/App.css'), + 'utf8' + ); assert(contents.includes(`.test[${output._scopeId}]`)); }); it('should produce a vue bundle using CSS modules', async function() { - let b = await bundle(__dirname + '/integration/vue-css-modules/App.vue'); + let b = await bundle( + path.join(__dirname, '/integration/vue-css-modules/App.vue') + ); await assertBundleTree(b, { type: 'js', @@ -168,13 +180,16 @@ describe('vue', function() { output.beforeCreate[0].call(ctx); assert.equal(typeof ctx.$style.red, 'string'); - let contents = await fs.readFile(__dirname + '/dist/App.css', 'utf8'); + let contents = await fs.readFile( + path.join(__dirname, '/dist/App.css'), + 'utf8' + ); assert(contents.includes('.' + ctx.$style.red)); }); it('should bundle nested components dynamically', async function() { let b = await bundle( - __dirname + '/integration/vue-nested-components/testcomp.vue' + path.join(__dirname, '/integration/vue-nested-components/testcomp.vue') ); await assertBundleTree(b, { @@ -214,9 +229,12 @@ describe('vue', function() { }); it('should produce a basic production vue bundle', async function() { - let b = await bundle(__dirname + '/integration/vue-basic/Basic.vue', { - production: true - }); + let b = await bundle( + path.join(__dirname, '/integration/vue-basic/Basic.vue'), + { + production: true + } + ); await assertBundleTree(b, { type: 'js', diff --git a/test/wasm.js b/test/wasm.js index 7f5a64538df..9fef9ef40cc 100644 --- a/test/wasm.js +++ b/test/wasm.js @@ -1,4 +1,5 @@ const assert = require('assert'); +const path = require('path'); const {bundle, run, assertBundleTree, deferred} = require('./utils'); describe('wasm', function() { @@ -9,9 +10,12 @@ describe('wasm', function() { for (const target of ['browser', 'node']) { describe(`--target=${target}`, function() { it('should preload a wasm file for a sync require', async function() { - let b = await bundle(__dirname + '/integration/wasm-sync/index.js', { - target - }); + let b = await bundle( + path.join(__dirname, '/integration/wasm-sync/index.js'), + { + target + } + ); await assertBundleTree(b, { name: 'index.js', @@ -39,9 +43,12 @@ describe('wasm', function() { }); it('should load a wasm file asynchronously with dynamic import', async function() { - let b = await bundle(__dirname + '/integration/wasm-async/index.js', { - target - }); + let b = await bundle( + path.join(__dirname, '/integration/wasm-async/index.js'), + { + target + } + ); await assertBundleTree(b, { name: 'index.js', @@ -68,9 +75,12 @@ describe('wasm', function() { }); it('should load a wasm file in parallel with a dynamic JS import', async function() { - let b = await bundle(__dirname + '/integration/wasm-dynamic/index.js', { - target - }); + let b = await bundle( + path.join(__dirname, '/integration/wasm-dynamic/index.js'), + { + target + } + ); await assertBundleTree(b, { name: 'index.js', diff --git a/test/watcher.js b/test/watcher.js index f5de60da3d3..438a1063c07 100644 --- a/test/watcher.js +++ b/test/watcher.js @@ -11,11 +11,16 @@ const { rimraf, ncp } = require('./utils'); +const {symlinkSync} = require('fs'); + +const inputDir = path.join(__dirname, '/input'); describe('watcher', function() { let b; beforeEach(async function() { - await rimraf(__dirname + '/input'); + await sleep(100); + await rimraf(inputDir); + await sleep(100); }); afterEach(function() { @@ -25,15 +30,15 @@ describe('watcher', function() { }); it('should rebuild on file change', async function() { - await ncp(__dirname + '/integration/commonjs', __dirname + '/input'); + await ncp(path.join(__dirname, '/integration/commonjs'), inputDir); - b = bundler(__dirname + '/input/index.js', {watch: true}); + b = bundler(path.join(inputDir, '/index.js'), {watch: true}); let bundle = await b.bundle(); let output = await run(bundle); assert.equal(output(), 3); await fs.writeFile( - __dirname + '/input/local.js', + path.join(inputDir, '/local.js'), 'exports.a = 5; exports.b = 5;' ); @@ -43,9 +48,9 @@ describe('watcher', function() { }); it('should re-generate bundle tree when files change', async function() { - await ncp(__dirname + '/integration/dynamic-hoist', __dirname + '/input'); + await ncp(path.join(__dirname, '/integration/dynamic-hoist'), inputDir); - b = bundler(__dirname + '/input/index.js', {watch: true}); + b = bundler(path.join(inputDir, '/index.js'), {watch: true}); let bundle = await b.bundle(); await assertBundleTree(bundle, { @@ -86,7 +91,7 @@ describe('watcher', function() { // change b.js so that it no longer depends on common.js. // This should cause common.js and dependencies to no longer be hoisted to the root bundle. - await fs.writeFile(__dirname + '/input/b.js', 'module.exports = 5;'); + await fs.writeFile(path.join(inputDir, '/b.js'), 'module.exports = 5;'); bundle = await nextBundle(b); await assertBundleTree(bundle, { @@ -120,33 +125,37 @@ describe('watcher', function() { }); it('should only re-package bundles that changed', async function() { - await ncp(__dirname + '/integration/dynamic-hoist', __dirname + '/input'); - b = bundler(__dirname + '/input/index.js', {watch: true}); + await ncp(path.join(__dirname, '/integration/dynamic-hoist'), inputDir); + b = bundler(path.join(inputDir, '/index.js'), {watch: true}); await b.bundle(); - let mtimes = (await fs.readdir(__dirname + '/dist')).map( + let mtimes = (await fs.readdir(path.join(__dirname, '/dist'))).map( f => - (nodeFS.statSync(__dirname + '/dist/' + f).mtime.getTime() / 1000) | 0 + (nodeFS.statSync(path.join(__dirname, '/dist/', f)).mtime.getTime() / + 1000) | + 0 ); await sleep(1100); // mtime only has second level precision await fs.writeFile( - __dirname + '/input/b.js', + path.join(inputDir, '/b.js'), 'module.exports = require("./common")' ); await nextBundle(b); - let newMtimes = (await fs.readdir(__dirname + '/dist')).map( + let newMtimes = (await fs.readdir(path.join(__dirname, '/dist'))).map( f => - (nodeFS.statSync(__dirname + '/dist/' + f).mtime.getTime() / 1000) | 0 + (nodeFS.statSync(path.join(__dirname, '/dist/', f)).mtime.getTime() / + 1000) | + 0 ); assert.deepEqual(mtimes.sort().slice(0, 2), newMtimes.sort().slice(0, 2)); assert.notEqual(mtimes[mtimes.length - 1], newMtimes[newMtimes.length - 1]); }); it('should unload assets that are orphaned', async function() { - await ncp(__dirname + '/integration/dynamic-hoist', __dirname + '/input'); - b = bundler(__dirname + '/input/index.js', {watch: true}); + await ncp(path.join(__dirname, '/integration/dynamic-hoist'), inputDir); + b = bundler(path.join(inputDir, '/index.js'), {watch: true}); let bundle = await b.bundle(); await assertBundleTree(bundle, { @@ -185,10 +194,13 @@ describe('watcher', function() { let output = await run(bundle); assert.equal(await output(), 7); - assert(b.loadedAssets.has(path.join(__dirname, '/input/common-dep.js'))); + assert(b.loadedAssets.has(path.join(inputDir, '/common-dep.js'))); // Get rid of common-dep.js - await fs.writeFile(__dirname + '/input/common.js', 'module.exports = 5;'); + await fs.writeFile( + path.join(inputDir, '/common.js'), + 'module.exports = 5;' + ); bundle = await nextBundle(b); await assertBundleTree(bundle, { @@ -226,41 +238,53 @@ describe('watcher', function() { output = await run(bundle); assert.equal(await output(), 13); - assert(!b.loadedAssets.has(path.join(__dirname, '/input/common-dep.js'))); + assert(!b.loadedAssets.has(path.join(inputDir, 'common-dep.js'))); }); it('should recompile all assets when a config file changes', async function() { - await ncp(__dirname + '/integration/babel', __dirname + '/input'); - b = bundler(__dirname + '/input/index.js', {watch: true}); + await ncp(path.join(__dirname, '/integration/babel'), inputDir); + b = bundler(path.join(inputDir, 'index.js'), {watch: true}); await b.bundle(); - let file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + let file = await fs.readFile( + path.join(__dirname, '/dist/index.js'), + 'utf8' + ); assert(!file.includes('function Foo')); assert(!file.includes('function Bar')); // Change babelrc, should recompile both files let babelrc = JSON.parse( - await fs.readFile(__dirname + '/input/.babelrc', 'utf8') + await fs.readFile(path.join(inputDir, '/.babelrc'), 'utf8') ); babelrc.presets[0][1].targets.browsers.push('IE >= 11'); await sleep(100); - await fs.writeFile(__dirname + '/input/.babelrc', JSON.stringify(babelrc)); + await fs.writeFile( + path.join(inputDir, '/.babelrc'), + JSON.stringify(babelrc) + ); await nextBundle(b); - file = await fs.readFile(__dirname + '/dist/index.js', 'utf8'); + file = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8'); assert(file.includes('function Foo')); assert(file.includes('function Bar')); }); it('should rebuild if the file behind a symlink changes', async function() { await ncp( - __dirname + '/integration/commonjs-with-symlinks/', - __dirname + '/input' + path.join(__dirname, '/integration/commonjs-with-symlinks/'), + 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(__dirname + '/input/src/index.js', { + b = bundler(path.join(inputDir, '/src/index.js'), { watch: true }); @@ -270,7 +294,7 @@ describe('watcher', function() { assert.equal(output(), 3); await fs.writeFile( - __dirname + '/input/local.js', + path.join(inputDir, '/local.js'), 'exports.a = 5; exports.b = 5;' );