Skip to content

Commit

Permalink
refactor(betterer 🔧): move to import() syntax for tests (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenomnomnominal authored Jul 16, 2023
1 parent 6c79098 commit ce62a47
Show file tree
Hide file tree
Showing 243 changed files with 745 additions and 547 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const OVERRIDE_RULES = {
'no-console': 2,
'@typescript-eslint/unbound-method': 0,
'@typescript-eslint/no-use-before-define': [2, { functions: false }],
'@typescript-eslint/member-ordering': 2
'@typescript-eslint/member-ordering': 2,
'@typescript-eslint/consistent-type-imports': [2, { prefer: 'type-imports', disallowTypeAnnotations: false }]
};

module.exports = {
Expand Down
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"betterer.tsconfigPath": "./tsconfig.json",
"cSpell.words": ["automerge"]
"cSpell.words": [
"automerge",
"bettere",
"betterertest",
"borks",
"bufferutil",
"commitlint",
"crlfs",
"Deserialiser",
"docgen",
"GOLDENS",
"hasher",
"initialise",
"Initialising",
"Lifecycles",
"loglevel",
"ngcc",
"reparse",
"stylelintrc",
"tsbuildinfo",
"tstemplate"
]
}
2 changes: 1 addition & 1 deletion goldens/api/angular.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts

import { BettererFileTest } from '@betterer/betterer';
import { CompilerOptions } from '@angular/compiler-cli';
import type { CompilerOptions } from '@angular/compiler-cli';

// @public
export function angular(configFilePath: string, extraCompilerOptions: CompilerOptions): BettererFileTest;
Expand Down
6 changes: 3 additions & 3 deletions goldens/api/betterer.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
```ts

import { BettererConstraintResult } from '@betterer/constraints';
import { BettererError } from '@betterer/errors';
import { BettererLogs } from '@betterer/logger';
import type { BettererConstraintResult } from '@betterer/constraints';
import type { BettererError } from '@betterer/errors';
import type { BettererLogs } from '@betterer/logger';

// Warning: (ae-missing-release-tag) "betterer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
6 changes: 3 additions & 3 deletions goldens/api/coverage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
```ts

import { BettererFileGlobs } from '@betterer/betterer';
import { BettererFilePatterns } from '@betterer/betterer';
import { BettererRun } from '@betterer/betterer';
import type { BettererFileGlobs } from '@betterer/betterer';
import type { BettererFilePatterns } from '@betterer/betterer';
import type { BettererRun } from '@betterer/betterer';
import { BettererTest } from '@betterer/betterer';

// @public
Expand Down
2 changes: 1 addition & 1 deletion goldens/api/eslint.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts

import { BettererFileTest } from '@betterer/betterer';
import { Linter } from 'eslint';
import type { Linter } from 'eslint';

// @public
export type BettererESLintRulesConfig = Record<string, Linter.RuleLevel | Linter.RuleLevelAndOptions>;
Expand Down
2 changes: 1 addition & 1 deletion goldens/api/logger.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```ts

import { DiffOptions } from 'jest-diff';
import type { DiffOptions } from 'jest-diff';

// @internal
export interface BettererLog {
Expand Down
2 changes: 1 addition & 1 deletion goldens/api/stylelint.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts

import { BettererFileTest } from '@betterer/betterer';
import { Configuration } from 'stylelint';
import type { Configuration } from 'stylelint';

// @public
export function stylelint(configOverrides: Partial<Configuration>): BettererFileTest;
Expand Down
2 changes: 1 addition & 1 deletion goldens/api/tasks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// <reference types="react" />

import { BettererError } from '@betterer/errors';
import { BettererLogger } from '@betterer/logger';
import type { BettererLogger } from '@betterer/logger';
import { FC } from '@betterer/render';

// @public
Expand Down
7 changes: 5 additions & 2 deletions packages/angular/src/angular.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { CompilerOptions, performCompilation, readConfiguration } from '@angular/compiler-cli';
import type { CompilerOptions } from '@angular/compiler-cli';
import type { DiagnosticWithLocation } from 'typescript';

import { performCompilation, readConfiguration } from '@angular/compiler-cli';
import { BettererFileTest } from '@betterer/betterer';
import { BettererError } from '@betterer/errors';
import { DiagnosticWithLocation, flattenDiagnosticMessageText } from 'typescript';
import { flattenDiagnosticMessageText } from 'typescript';

/**
* @public Use this test to incrementally introduce {@link https://angular.io/guide/angular-compiler-options | **Angular** compiler configuration }
Expand Down
11 changes: 7 additions & 4 deletions packages/betterer/src/betterer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { debug } from '@phenomnomnominal/debug';

import {
import type {
BettererOptionsRunner,
BettererOptionsStart,
BettererOptionsResults,
BettererOptionsWatch,
BettererOptionsMerge
} from './config';
import { BettererRunner, BettererRunnerΩ } from './runner';
import { BettererMergerΩ, BettererResultsSummary, BettererResultsSummaryΩ } from './results';
import { BettererSuiteSummary } from './suite';
import type { BettererRunner } from './runner';
import type { BettererResultsSummary } from './results';
import type { BettererSuiteSummary } from './suite';

import { BettererRunnerΩ } from './runner';
import { BettererMergerΩ, BettererResultsSummaryΩ } from './results';

/**
* @public Run **Betterer** with the given options.
Expand Down
23 changes: 13 additions & 10 deletions packages/betterer/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { BettererError } from '@betterer/errors';
import assert from 'assert';
import * as os from 'os';
import * as path from 'path';

import { BettererVersionControlWorker, read } from '../fs';
import { registerExtensions } from './register';
import { BettererReporter, loadReporters, loadSilentReporter } from '../reporters';
import { isBoolean, isNumber, isRegExp, isString, isUndefined } from '../utils';
import {
import type { BettererVersionControlWorker } from '../fs';
import type { BettererReporter } from '../reporters';
import type {
BettererConfig,
BettererConfigBase,
BettererConfigMerge,
Expand All @@ -21,6 +14,16 @@ import {
BettererWorkerRunConfig
} from './types';

import { BettererError } from '@betterer/errors';
import assert from 'assert';
import * as os from 'os';
import * as path from 'path';

import { read } from '../fs';
import { registerExtensions } from './register';
import { loadReporters, loadSilentReporter } from '../reporters';
import { isBoolean, isNumber, isRegExp, isString, isUndefined } from '../utils';

const TOTAL_CPUS = os.cpus().length;

export async function createConfig(
Expand Down
2 changes: 1 addition & 1 deletion packages/betterer/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BettererReporter } from '../reporters';
import type { BettererReporter } from '../reporters';

/**
* @public An array of {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | Regular Expressions }
Expand Down
6 changes: 3 additions & 3 deletions packages/betterer/src/context/context-summary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BettererConfig } from '../config';
import { BettererSuiteSummariesΩ, BettererSuiteSummaryΩ } from '../suite';
import { BettererContextSummary } from './types';
import type { BettererConfig } from '../config';
import type { BettererSuiteSummariesΩ, BettererSuiteSummaryΩ } from '../suite';
import type { BettererContextSummary } from './types';

export class BettererContextSummaryΩ implements BettererContextSummary {
constructor(public readonly config: BettererConfig, public readonly suites: BettererSuiteSummariesΩ) {}
Expand Down
24 changes: 14 additions & 10 deletions packages/betterer/src/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { BettererError } from '@betterer/errors';
import { FSWatcher } from 'chokidar';

import { BettererConfig, BettererOptionsOverride, overrideConfig } from '../config';
import { BettererFilePaths, BettererFileResolverΩ, BettererVersionControlWorker } from '../fs';
import { BettererReporterΩ } from '../reporters';
import { BettererResultsFileΩ } from '../results';
import type { BettererError } from '@betterer/errors';
import type { FSWatcher } from 'chokidar';

import type { BettererConfig, BettererOptionsOverride } from '../config';
import type { BettererFilePaths, BettererVersionControlWorker } from '../fs';
import type { BettererReporterΩ } from '../reporters';
import type { BettererResultsFileΩ } from '../results';
import type { BettererSuiteSummariesΩ, BettererSuiteSummary } from '../suite';
import type { BettererGlobals } from '../types';
import type { BettererContext, BettererContextStarted, BettererContextSummary } from './types';

import { overrideConfig } from '../config';
import { BettererFileResolverΩ } from '../fs';
import { BettererRunWorkerPoolΩ, BettererRunΩ, createWorkerRunConfig } from '../run';
import { BettererSuiteΩ, BettererSuiteSummariesΩ, BettererSuiteSummary } from '../suite';
import { BettererSuiteΩ } from '../suite';
import { loadTestMeta } from '../test';
import { defer } from '../utils';
import { BettererGlobals } from '../types';
import { BettererContextSummaryΩ } from './context-summary';
import { BettererContext, BettererContextStarted, BettererContextSummary } from './types';

export class BettererContextΩ implements BettererContext {
public readonly config: BettererConfig;
Expand Down
6 changes: 3 additions & 3 deletions packages/betterer/src/context/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BettererError } from '@betterer/errors';
import type { BettererError } from '@betterer/errors';

import { BettererConfig, BettererOptionsOverride } from '../config';
import { BettererSuiteSummaries, BettererSuiteSummary } from '../suite';
import type { BettererConfig, BettererOptionsOverride } from '../config';
import type { BettererSuiteSummaries, BettererSuiteSummary } from '../suite';

/**
* @public The context of a set of test suite runs.
Expand Down
11 changes: 6 additions & 5 deletions packages/betterer/src/fs/file-cache.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import assert from 'assert';
import path from 'path';
import { normalisedPath } from '../utils';
import { read } from './reader';
import {
import type {
BettererFilePaths,
BettererTestCacheMap,
BettererFileCache,
BettererFileHashMap,
BettererCacheFile
} from './types';

import assert from 'assert';
import path from 'path';
import { normalisedPath } from '../utils';
import { read } from './reader';
import { write } from './writer';

const BETTERER_CACHE_VERSION = 2;
Expand Down
13 changes: 7 additions & 6 deletions packages/betterer/src/fs/file-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import assert from 'assert';
import minimatch from 'minimatch';
import * as path from 'path';

import { flatten, normalisedPath } from '../utils';
import {
import type {
BettererFileGlobs,
BettererFilePaths,
BettererFilePatterns,
BettererFileResolver,
BettererVersionControlWorker
} from './types';

import assert from 'assert';
import minimatch from 'minimatch';
import * as path from 'path';

import { flatten, normalisedPath } from '../utils';

export class BettererFileResolverΩ implements BettererFileResolver {
private _excluded: Array<RegExp> = [];
private _included: Array<string> = [];
Expand Down
7 changes: 5 additions & 2 deletions packages/betterer/src/fs/git.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { SimpleGit } from 'simple-git';

import type { BettererFilePaths, BettererVersionControl } from './types';

import { BettererError } from '@betterer/errors';
import assert from 'assert';
import { promises as fs } from 'fs';
import path from 'path';
import simpleGit, { SimpleGit } from 'simple-git';
import simpleGit from 'simple-git';

import { createHash } from '../hasher';
import { normalisedPath } from '../utils';
import { BettererFileCacheΩ } from './file-cache';
import { read } from './reader';
import { BettererFilePaths, BettererVersionControl } from './types';

export class BettererGitΩ implements BettererVersionControl {
private _cache: BettererFileCacheΩ | null = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/betterer/src/fs/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WorkerRequireModule, WorkerRequireModuleAsync } from '@phenomnomnominal/worker-require';
import type { WorkerRequireModule, WorkerRequireModuleAsync } from '@phenomnomnominal/worker-require';

/**
* @public An array of {@link https://www.npmjs.com/package/glob#user-content-glob-primer | glob }
Expand Down
4 changes: 2 additions & 2 deletions packages/betterer/src/fs/version-control.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { workerRequire } from '@phenomnomnominal/worker-require';
import type { BettererVersionControlWorker, BettererVersionControlWorkerModule } from './types';

import { BettererVersionControlWorker, BettererVersionControlWorkerModule } from './types';
import { workerRequire } from '@phenomnomnominal/worker-require';

export function createVersionControl(): BettererVersionControlWorker {
const worker = workerRequire<BettererVersionControlWorkerModule>('./version-control-worker');
Expand Down
4 changes: 2 additions & 2 deletions packages/betterer/src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BettererError } from '@betterer/errors';
import type { BettererError } from '@betterer/errors';
import type { BettererGlobals } from './types';

import { createConfig } from './config';
import { createVersionControl } from './fs';
import { loadDefaultReporter } from './reporters';
import { BettererResultsFileΩ } from './results';
import { BettererGlobals } from './types';

export async function createGlobals(options: unknown = {}): Promise<BettererGlobals> {
const reporter = loadDefaultReporter();
Expand Down
5 changes: 3 additions & 2 deletions packages/betterer/src/reporters/loader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { BettererOptionsReporters } from '../config';
import type { BettererReporter, BettererReporterModule } from './types';

import { BettererError } from '@betterer/errors';
import * as path from 'path';

import { BettererOptionsReporters } from '../config';
import { requireUncached } from '../require';
import { isFunction, isString } from '../utils';
import { BettererReporterΩ } from './reporter';
import { BettererReporter, BettererReporterModule } from './types';

const DEFAULT_REPORTER = '@betterer/reporter';
const HOOK_NAMES = Object.getOwnPropertyNames(BettererReporterΩ.prototype) as ReadonlyArray<keyof BettererReporter>;
Expand Down
12 changes: 6 additions & 6 deletions packages/betterer/src/reporters/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BettererError } from '@betterer/errors';
import type { BettererError } from '@betterer/errors';

import { BettererContext } from '../context';
import { BettererContextSummary } from '../context/types';
import { BettererRun, BettererRunSummary } from '../run';
import { BettererSuite, BettererSuiteSummary } from '../suite';
import { BettererReporter } from './types';
import type { BettererContext } from '../context';
import type { BettererContextSummary } from '../context/types';
import type { BettererRun, BettererRunSummary } from '../run';
import type { BettererSuite, BettererSuiteSummary } from '../suite';
import type { BettererReporter } from './types';

export class BettererReporterΩ implements BettererReporter {
constructor(private _reporters: Array<BettererReporter>) {}
Expand Down
8 changes: 4 additions & 4 deletions packages/betterer/src/reporters/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BettererError } from '@betterer/errors';
import type { BettererError } from '@betterer/errors';

import { BettererContext, BettererContextSummary } from '../context';
import { BettererRun, BettererRunSummary } from '../run';
import { BettererSuiteSummary, BettererSuite } from '../suite';
import type { BettererContext, BettererContextSummary } from '../context';
import type { BettererRun, BettererRunSummary } from '../run';
import type { BettererSuiteSummary, BettererSuite } from '../suite';

/**
* @public The interface for hooking into **Betterer**'s reporter system.
Expand Down
3 changes: 2 additions & 1 deletion packages/betterer/src/results/merge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BettererResultsSerialised } from './types';

import { requireText } from './require';
import { BettererResultsSerialised } from './types';

/**
* Takes two strings of JavaScript, evaluates their contents, and merges the results,
Expand Down
6 changes: 4 additions & 2 deletions packages/betterer/src/results/merger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BettererOptionsMerge, createMergeConfig } from '../config';
import type { BettererOptionsMerge } from '../config';
import type { BettererResultsSerialised } from './types';

import { createMergeConfig } from '../config';
import { write } from '../fs';
import { mergeResults } from './merge';
import { parseResults } from './parse';
import { printResults } from './print';
import { BettererResultsSerialised } from './types';

export class BettererMergerΩ {
private constructor(private _contents: Array<string>, private _resultsPath: string) {}
Expand Down
Loading

0 comments on commit ce62a47

Please sign in to comment.