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
29 changes: 29 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,29 @@
// Missing flow types for node:assert
declare module "assert/strict" {
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;
strictEqual(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;
rejects(
block: Function,
error?: Function | RegExp | (err: any) => boolean,
message?: string
): void;
doesNotThrow(block: Function, message?: string): void;
ifError(value: any): void;
AssertionError: typeof AssertionError;
...
}
}
1 change: 1 addition & 0 deletions flow-typed/npm/rimraf_v5.x.x.js
Original file line number Diff line number Diff line change
@@ -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,
...
};
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');

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';
12 changes: 6 additions & 6 deletions packages/core/core/src/Dependency.js
Original file line number Diff line number Diff line change
@@ -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);
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', () => {
@@ -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',
@@ -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
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';

@@ -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');
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 {
@@ -10,6 +11,7 @@ import {
removeDistDirectory,
run,
} from '@atlaspack/test-utils';
import type {InitialAtlaspackOptions} from '@atlaspack/types';

describe('bundle-text:', function () {
beforeEach(async () => {
@@ -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)`
@@ -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',
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';
@@ -885,10 +886,16 @@ describe('bundler', function () {
},
]);

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

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

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);
@@ -950,6 +957,7 @@ describe('bundler', function () {
.find(
(bundle) => !bundle.getMainEntry() && bundle.name.includes('runtime'),
);
if (!aManifestBundle) return assert(false);

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

let aBundleManifestAssetCode = await aBundleManifestAsset.getCode();

// Assert the a.js manifest bundle is aware of all the b.js bundles
@@ -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(false);

const contents = overlayFS.readFileSync(index.filePath, 'utf8');
assert(
!contents.includes('async value'),
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';
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';
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 {
@@ -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(false);

let bJS = bBundles.find((bundle) => bundle.type === 'js');
if (!bJS) return assert(false);

assert(/index\.[a-f0-9]*\.js/.test(path.basename(aJS.filePath)));
assert.equal(aJS.name, bJS.name);
},
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 {
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';
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,
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';

@@ -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,
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';
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';
Loading