Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliability: Flow types for tests (part 3) #278

Merged
merged 19 commits into from
Dec 12, 2024
55 changes: 55 additions & 0 deletions flow-typed/node/assert.js
Copy link
Contributor Author

@alshdavid alshdavid Dec 12, 2024

Choose a reason for hiding this comment

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

flow types missing for assert.rejects and assert.fail, using override to pass type check

Original file line number Diff line number Diff line change
@@ -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;
...
}
}
1 change: 1 addition & 0 deletions flow-typed/npm/rimraf_v5.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'rimraf' {

declare module.exports: {
(f: string, opts?: Options): Promise<boolean>,
rimraf(f: string, opts?: Options): Promise<boolean>,
sync(path: string, opts?: Options): boolean,
...
};
Expand Down
7 changes: 4 additions & 3 deletions packages/core/cache/test/LMDBLiteCache.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from 'node:path';
// @flow
import * as path from 'path';
import {tmpdir} from 'os';
import {LMDBLiteCache} from '../src/index';
import {deserialize, serialize} from 'node:v8';
import assert from 'node:assert';
import {deserialize, serialize} from 'v8';
import assert from 'assert';

const cacheDir = path.join(tmpdir(), 'lmdb-lite-cache-tests');

Expand Down
1 change: 1 addition & 0 deletions packages/core/codeframe/test/codeframe.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {readFileSync} from 'fs';
import {join as joinPath} from 'path';
Expand Down
12 changes: 6 additions & 6 deletions packages/core/core/src/Dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export function createDependencyId({
priority,
packageConditions,
}: {|
sourceAssetId: string | void,
sourceAssetId?: string | void,
specifier: DependencySpecifier,
env: Environment,
target: Target | void,
pipeline: ?string,
target?: Target | void,
pipeline?: ?string,
specifierType: $Keys<typeof SpecifierType>,
bundleBehavior: ?IBundleBehavior,
priority: $Keys<typeof Priority> | void,
packageConditions: Array<string> | void,
bundleBehavior?: ?IBundleBehavior,
priority?: $Keys<typeof Priority> | void,
packageConditions?: Array<string> | void,
|}): string {
assert(typeof specifierType === 'string');
assert(typeof priority === 'string' || priority == null);
Expand Down
6 changes: 4 additions & 2 deletions packages/core/core/test/Dependency.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
import expect from 'expect';
import {createDependencyId} from '../src/Dependency';
import {createEnvironment} from '../src/Environment';
import type {ProjectPath} from '../src/projectPath';

describe('Dependency', () => {
describe('createDependencyId', () => {
Expand All @@ -25,7 +27,7 @@ describe('Dependency', () => {
specifierType: 'esm',
target: {
name: 'test-1234',
distDir: 'dist-dir',
distDir: (('dist-dir': any): ProjectPath),
env: createEnvironment(),
publicUrl: 'public-url',
source: '1234',
Expand All @@ -37,7 +39,7 @@ describe('Dependency', () => {
specifierType: 'esm',
target: {
name: 'test-1234',
distDir: 'dist-dir',
distDir: (('dist-dir': any): ProjectPath),
env: createEnvironment(),
publicUrl: 'public-url',
source: '5678', // <- this is different
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {getAssetGraph} from '../../src/requests/AssetGraphRequestRust';

Expand All @@ -8,8 +9,8 @@ describe('AssetGraphRequestRust -> getAssetGraph', function () {
const indexAsset = assetGraph.getNodeByContentKey('79c128d4f549c408');
const libraryDep = assetGraph.getNodeByContentKey('cfe74f65a41af1a7');

assert(indexAsset?.type === 'asset');
assert(libraryDep?.type === 'dependency');
if (indexAsset?.type !== 'asset') return assert(false);
if (libraryDep?.type !== 'dependency') return assert(false);

assert.equal(indexAsset.value.filePath, '/index.ts');
assert.equal(libraryDep.value.specifier, './library');
Expand Down
10 changes: 6 additions & 4 deletions packages/core/integration-tests/test/bundle-text.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {join} from 'path';
import {
Expand All @@ -10,6 +11,7 @@ import {
removeDistDirectory,
run,
} from '@atlaspack/test-utils';
import type {InitialAtlaspackOptions} from '@atlaspack/types';

describe('bundle-text:', function () {
beforeEach(async () => {
Expand Down Expand Up @@ -164,15 +166,15 @@ describe('bundle-text:', function () {
describe(`when scope hoisting is ${
scopeHoist ? 'enabled' : 'disabled'
}`, () => {
let options = scopeHoist
let options: InitialAtlaspackOptions = scopeHoist
? {
defaultTargetOptions: {
isLibrary: true,
outputFormat: 'esmodule',
shouldScopeHoist: true,
},
}
: {};
: Object.freeze({});

it('can be used with an import that points to the same asset', async function () {
await fsFixture(overlayFS, __dirname)`
Expand Down Expand Up @@ -201,8 +203,8 @@ describe('bundle-text:', function () {
assets: [
'index.js',
'main.js',
!scopeHoist && 'esmodule-helpers.js',
].filter(Boolean),
...(!scopeHoist ? ['esmodule-helpers.js'] : []),
],
},
{
type: 'js',
Expand Down
16 changes: 14 additions & 2 deletions packages/core/integration-tests/test/bundler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import path from 'path';
import assert from 'assert';
import Logger from '@atlaspack/logger';
Expand Down Expand Up @@ -885,10 +886,16 @@ describe('bundler', function () {
},
]);

let assetBar = findAsset(b, 'bar.js');
if (!assetBar) return assert.fail();

let assetC = findAsset(b, 'c.js');
if (!assetC) return assert.fail();

assert(
b
.getReferencedBundles(b.getBundlesWithAsset(findAsset(b, 'bar.js'))[0])
.includes(b.getBundlesWithAsset(findAsset(b, 'c.js'))[0]),
.getReferencedBundles(b.getBundlesWithAsset(assetBar)[0])
.includes(b.getBundlesWithAsset(assetC)[0]),
);

await run(b);
Expand Down Expand Up @@ -950,6 +957,7 @@ describe('bundler', function () {
.find(
(bundle) => !bundle.getMainEntry() && bundle.name.includes('runtime'),
);
if (!aManifestBundle) return assert.fail();

let bBundles = b
.getBundles()
Expand All @@ -962,6 +970,8 @@ describe('bundler', function () {
stop();
}
});
if (!aBundleManifestAsset) return assert.fail();

let aBundleManifestAssetCode = await aBundleManifestAsset.getCode();

// Assert the a.js manifest bundle is aware of all the b.js bundles
Expand Down Expand Up @@ -1323,6 +1333,8 @@ describe('bundler', function () {

// Asset should not be inlined
const index = b.getBundles().find((b) => b.name.startsWith('index'));
if (!index) return assert.fail();

const contents = overlayFS.readFileSync(index.filePath, 'utf8');
assert(
!contents.includes('async value'),
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/compressors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import zlib from 'zlib';
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/config-merging.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import {bundle, describe, it, run, outputFS} from '@atlaspack/test-utils';
import assert from 'assert';
import path from 'path';
Expand Down
17 changes: 15 additions & 2 deletions packages/core/integration-tests/test/contentHashing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/data-url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {join} from 'path';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/encodedURI.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import {join} from 'path';
import {bundle, describe, it, outputFS, distDir} from '@atlaspack/test-utils';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/integration-tests/test/feature-flags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import assert from 'assert';
import path from 'node:path';
import path from 'path';
import {rimraf} from 'rimraf';
import {
bundle,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/integration-tests/test/globals.js
Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultTargetOptions.context is not on InitialOptions and does not appear to be used within core

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/glsl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import fs from 'fs';
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/graphql.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import assert from 'assert';
import path from 'path';
import {bundle, describe, it, run} from '@atlaspack/test-utils';
Expand Down
Loading
Loading