diff --git a/flow-typed/node/assert.js b/flow-typed/node/assert.js new file mode 100644 index 000000000..d72d22373 --- /dev/null +++ b/flow-typed/node/assert.js @@ -0,0 +1,55 @@ +// Missing flow types for node:assert +declare module "assert" { + declare class AssertionError extends Error {} + declare type AssertStrict = { + (value: any, message?: string): void; + ok(value: any, message?: string): void; + fail(message?: string | Error): void; + // deprecated since v10.15 + // fail(actual: any, expected: any, message: string, operator: string): void; + equal(actual: any, expected: any, message?: string): void; + notEqual(actual: any, expected: any, message?: string): void; + deepEqual(actual: any, expected: any, message?: string): void; + notDeepEqual(actual: any, expected: any, message?: string): void; + throws( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void; + doesNotThrow(block: Function, message?: string): void; + ifError(value: any): void; + AssertionError: typeof AssertionError; + strict: AssertStrict; + ... + } + declare module.exports: { + (value: any, message?: string): void, + ok(value: any, message?: string): void, + fail(message?: string | Error): void, + // deprecated since v10.15 + // fail(actual: any, expected: any, message: string, operator: string): void, + equal(actual: any, expected: any, message?: string): void, + notEqual(actual: any, expected: any, message?: string): void, + deepEqual(actual: any, expected: any, message?: string): void, + notDeepEqual(actual: any, expected: any, message?: string): void, + strictEqual(actual: any, expected: any, message?: string): void, + notStrictEqual(actual: any, expected: any, message?: string): void, + deepStrictEqual(actual: any, expected: any, message?: string): void, + notDeepStrictEqual(actual: any, expected: any, message?: string): void, + throws( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void, + doesNotThrow(block: Function, message?: string): void, + rejects( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void; + ifError(value: any): void, + AssertionError: typeof AssertionError, + strict: AssertStrict; + ... + } +} diff --git a/packages/core/integration-tests/test/bundler.js b/packages/core/integration-tests/test/bundler.js index a234c6076..e6b8687eb 100644 --- a/packages/core/integration-tests/test/bundler.js +++ b/packages/core/integration-tests/test/bundler.js @@ -887,10 +887,10 @@ describe('bundler', function () { ]); let assetBar = findAsset(b, 'bar.js'); - if (!assetBar) return assert(false); + if (!assetBar) return assert.fail(); let assetC = findAsset(b, 'c.js'); - if (!assetC) return assert(false); + if (!assetC) return assert.fail(); assert( b @@ -957,7 +957,7 @@ describe('bundler', function () { .find( (bundle) => !bundle.getMainEntry() && bundle.name.includes('runtime'), ); - if (!aManifestBundle) return assert(false); + if (!aManifestBundle) return assert.fail(); let bBundles = b .getBundles() @@ -970,7 +970,7 @@ describe('bundler', function () { stop(); } }); - if (!aBundleManifestAsset) return assert(false); + if (!aBundleManifestAsset) return assert.fail(); let aBundleManifestAssetCode = await aBundleManifestAsset.getCode(); @@ -1333,7 +1333,7 @@ describe('bundler', function () { // Asset should not be inlined const index = b.getBundles().find((b) => b.name.startsWith('index')); - if (!index) return assert(false); + if (!index) return assert.fail(); const contents = overlayFS.readFileSync(index.filePath, 'utf8'); assert( diff --git a/packages/core/integration-tests/test/contentHashing.js b/packages/core/integration-tests/test/contentHashing.js index b3bedd284..87e4cc67e 100644 --- a/packages/core/integration-tests/test/contentHashing.js +++ b/packages/core/integration-tests/test/contentHashing.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import { @@ -99,11 +100,19 @@ describe('content hashing', function () { async () => { let a = await _bundle( path.join(__dirname, 'integration/hash-distDir/a/index.html'), - {sourceMaps: true}, + { + defaultTargetOptions: { + sourceMaps: true, + }, + }, ); let b = await _bundle( path.join(__dirname, 'integration/hash-distDir/b/index.html'), - {sourceMaps: true}, + { + defaultTargetOptions: { + sourceMaps: true, + }, + }, ); let aBundles = a.getBundles(); @@ -113,7 +122,11 @@ describe('content hashing', function () { assert.equal(bBundles.length, 2); let aJS = aBundles.find((bundle) => bundle.type === 'js'); + if (!aJS) return assert.fail(); + let bJS = bBundles.find((bundle) => bundle.type === 'js'); + if (!bJS) return assert.fail(); + assert(/index\.[a-f0-9]*\.js/.test(path.basename(aJS.filePath))); assert.equal(aJS.name, bJS.name); }, diff --git a/packages/core/integration-tests/test/globals.js b/packages/core/integration-tests/test/globals.js index 885efb0a2..f50904f2c 100644 --- a/packages/core/integration-tests/test/globals.js +++ b/packages/core/integration-tests/test/globals.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; @@ -58,7 +59,6 @@ describe('globals', function () { it('when scope hoisting is disabled', async function () { let bundleGraph = await bundle(path.join(dir, 'index.js'), { defaultTargetOptions: { - context: 'browser', shouldScopeHoist: false, }, inputFS: overlayFS, @@ -84,7 +84,6 @@ describe('globals', function () { it.v2('when scope hoisting is enabled', async function () { let bundleGraph = await bundle(path.join(dir, 'index.js'), { defaultTargetOptions: { - context: 'browser', shouldScopeHoist: true, }, inputFS: overlayFS, diff --git a/packages/core/integration-tests/test/html.js b/packages/core/integration-tests/test/html.js index 6a8ae7218..cf1373b1d 100644 --- a/packages/core/integration-tests/test/html.js +++ b/packages/core/integration-tests/test/html.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import { assertBundles, @@ -94,6 +95,8 @@ describe('html', function () { assert(html.includes('https://unpkg.com/parcel-bundler')); let iconsBundle = b.getBundles().find((b) => b.name.startsWith('icons')); + if (!iconsBundle) return assert.fail(); + assert( html.includes('/' + path.basename(iconsBundle.filePath) + '#icon-code'), ); @@ -121,8 +124,8 @@ describe('html', function () { }, ]); - assert(await outputFS.exists(path.join(distDir, 'a.html'), 'utf8')); - assert(await outputFS.exists(path.join(distDir, 'b.html'), 'utf8')); + assert(await outputFS.exists(path.join(distDir, 'a.html'))); + assert(await outputFS.exists(path.join(distDir, 'b.html'))); }); it('should find href attr when not first', async function () { @@ -462,7 +465,9 @@ describe('html', function () { let b = await bundle( path.join(__dirname, '/integration/html-css-js/index.html'), { - hmr: true, + // Test is skipped, hmr does not exist on InitialOptions + // Leaving it here to fix when the test is enabled in future + // hmr: true, }, ); @@ -956,23 +961,25 @@ describe('html', function () { path.join(__dirname, '/integration/webmanifest/index.html'), ); - assertBundles(b, { - name: 'index.html', - assets: ['index.html'], - childBundles: [ - { - type: 'webmanifest', - assets: ['manifest.webmanifest'], - childBundles: [ - { - type: 'txt', - assets: ['some.txt'], - childBundles: [], - }, - ], - }, - ], - }); + assertBundles(b, [ + { + name: 'index.html', + assets: ['index.html'], + childBundles: [ + { + type: 'webmanifest', + assets: ['manifest.webmanifest'], + childBundles: [ + { + type: 'txt', + assets: ['some.txt'], + childBundles: [], + }, + ], + }, + ], + }, + ]); }); it.skip("should treat webmanifest as an entry module so it doesn't get content hashed", async function () { @@ -980,16 +987,18 @@ describe('html', function () { path.join(__dirname, '/integration/html-manifest/index.html'), ); - assertBundles(b, { - name: 'index.html', - assets: ['index.html'], - childBundles: [ - { - type: 'webmanifest', - assets: ['manifest.webmanifest'], - }, - ], - }); + assertBundles(b, [ + { + name: 'index.html', + assets: ['index.html'], + childBundles: [ + { + type: 'webmanifest', + assets: ['manifest.webmanifest'], + }, + ], + }, + ]); const html = await outputFS.readFile( path.join(__dirname, '/dist/index.html'), @@ -1210,11 +1219,10 @@ describe('html', function () { ]); let bundles = b.getBundles(); + let foundBundle = bundles.find((bundle) => bundle.type === 'html'); + if (!foundBundle) return assert.fail(); - let html = await outputFS.readFile( - bundles.find((bundle) => bundle.type === 'html').filePath, - 'utf8', - ); + let html = await outputFS.readFile(foundBundle.filePath, 'utf8'); let urls = [...html.matchAll(/url\(([^)]*)\)/g)].map((m) => m[1]); assert.strictEqual(urls.length, 2); @@ -1412,7 +1420,7 @@ describe('html', function () { for (let scopeHoist of [false, true]) { it.v2( 'should expose top level declarations globally in inline