diff --git a/.xo-config.json b/.xo-config.json new file mode 100644 index 000000000..3d1a5f220 --- /dev/null +++ b/.xo-config.json @@ -0,0 +1,76 @@ +{ + "ignores": [ + "media/**", + "test/config/fixtures/config-errors/test.js", + "test-tap/fixture/snapshots/test-sourcemaps/build/**", + "test-tap/fixture/report/edgecases/ast-syntax-error.cjs" + ], + "rules": { + "import/no-anonymous-default-export": "off", + "import/no-mutable-exports": "off", + "import/order": [ + "error", + { + "alphabetize": { + "order": "asc" + }, + "newlines-between": "always" + } + ], + "import/newline-after-import": "error", + "node/no-unsupported-features/es-syntax": "off", + "no-use-extend-native/no-use-extend-native": "off" + }, + "overrides": [ + { + "files": "index.d.ts", + "rules": { + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/method-signature-style": "off", + "@typescript-eslint/prefer-readonly-parameter-types": "off", + "@typescript-eslint/prefer-function-type": "off", + "@typescript-eslint/unified-signatures": "off" + } + }, + { + "files": "plugin.d.ts", + "rules": { + "node/prefer-global/url": "off" + } + }, + { + "files": "test-{d,tap}/**/*.ts", + "rules": { + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-unsafe-call": "off", + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/no-unsafe-return": "off", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/prefer-readonly-parameter-types": "off", + "import/extensions": "off", + "no-unused-vars": "off" + } + }, + { + "files": "test-tap/**/*.js", + "rules": { + "promise/prefer-await-to-then": "off", + "unicorn/error-message": "off", + "unicorn/no-array-reduce": "off", + "unicorn/prevent-abbreviations": "off" + } + }, + { + "files": [ + "test-tap/fixture/**", + "test/**/fixtures/**" + ], + "rules": { + "ava/no-todo-test": "off", + "import/no-extraneous-dependencies": "off", + "import/no-unresolved": "off" + } + } + ] +} diff --git a/entrypoints/cli.mjs b/entrypoints/cli.mjs index 9f77d9202..aaa436e54 100755 --- a/entrypoints/cli.mjs +++ b/entrypoints/cli.mjs @@ -1,3 +1,4 @@ #!/usr/bin/env node -import * as cli from '../lib/cli.js'; // eslint-disable-line import/extensions -cli.run(); +import run from '../lib/cli.js'; + +run(); diff --git a/entrypoints/eslint-plugin-helper.cjs b/entrypoints/eslint-plugin-helper.cjs index 23e370ab2..96544defc 100644 --- a/entrypoints/eslint-plugin-helper.cjs +++ b/entrypoints/eslint-plugin-helper.cjs @@ -4,7 +4,14 @@ const url = require('url'); const v8 = require('v8'); const {Worker} = require('worker_threads'); -const {classify, hasExtension, isHelperish, matches, normalizeFileForMatching, normalizePatterns} = require('../lib/globs'); +const { + classify, + hasExtension, + isHelperish, + matches, + normalizeFileForMatching, + normalizePatterns +} = require('../lib/glob-helpers.cjs'); const MAX_DATA_LENGTH_EXCLUSIVE = 100 * 1024; // Allocate 100 KiB to exchange globs. diff --git a/entrypoints/main.cjs b/entrypoints/main.cjs index 0ae4ff434..c0a5562b4 100644 --- a/entrypoints/main.cjs +++ b/entrypoints/main.cjs @@ -1,2 +1,2 @@ 'use strict'; -module.exports = require('../lib/worker/main'); +module.exports = require('../lib/worker/main.cjs'); diff --git a/entrypoints/main.mjs b/entrypoints/main.mjs index 387c84e5c..f622a2e08 100644 --- a/entrypoints/main.mjs +++ b/entrypoints/main.mjs @@ -1,2 +1,3 @@ -import test from '../lib/worker/main.js'; // eslint-disable-line import/extensions +import test from '../lib/worker/main.cjs'; + export default test; diff --git a/entrypoints/plugin.cjs b/entrypoints/plugin.cjs index 673a390da..9c594ad0a 100644 --- a/entrypoints/plugin.cjs +++ b/entrypoints/plugin.cjs @@ -1,2 +1,2 @@ 'use strict'; -module.exports = require('../lib/worker/plugin'); +module.exports = require('../lib/worker/plugin.cjs'); diff --git a/entrypoints/plugin.mjs b/entrypoints/plugin.mjs index a2f0e51ae..f777eb4f7 100644 --- a/entrypoints/plugin.mjs +++ b/entrypoints/plugin.mjs @@ -1,4 +1,4 @@ -'use strict'; -import * as plugin from '../lib/worker/plugin.js'; // eslint-disable-line import/extensions +import * as plugin from '../lib/worker/plugin.cjs'; + const {registerSharedWorker} = plugin; export {registerSharedWorker}; diff --git a/lib/api.js b/lib/api.js index bb630d288..d82d2937c 100644 --- a/lib/api.js +++ b/lib/api.js @@ -1,24 +1,25 @@ -'use strict'; -const fs = require('fs'); -const path = require('path'); -const os = require('os'); -const commonPathPrefix = require('common-path-prefix'); -const resolveCwd = require('resolve-cwd'); -const debounce = require('lodash/debounce'); -const arrify = require('arrify'); -const ms = require('ms'); -const chunkd = require('chunkd'); -const Emittery = require('emittery'); -const pMap = require('p-map'); -const tempDir = require('temp-dir'); -const globs = require('./globs'); -const isCi = require('./is-ci'); -const RunStatus = require('./run-status'); -const fork = require('./fork'); -const serializeError = require('./serialize-error'); -const {getApplicableLineNumbers} = require('./line-numbers'); -const sharedWorkers = require('./plugin-support/shared-workers'); -const scheduler = require('./scheduler'); +import fs from 'fs'; +import os from 'os'; +import path from 'path'; + +import arrify from 'arrify'; +import chunkd from 'chunkd'; +import commonPathPrefix from 'common-path-prefix'; +import Emittery from 'emittery'; +import debounce from 'lodash/debounce.js'; +import ms from 'ms'; +import pMap from 'p-map'; +import resolveCwd from 'resolve-cwd'; +import tempDir from 'temp-dir'; + +import fork from './fork.js'; +import * as globs from './globs.js'; +import isCi from './is-ci.js'; +import {getApplicableLineNumbers} from './line-numbers.js'; +import {observeWorkerProcess} from './plugin-support/shared-workers.js'; +import RunStatus from './run-status.js'; +import scheduler from './scheduler.js'; +import serializeError from './serialize-error.js'; function resolveModules(modules) { return arrify(modules).map(name => { @@ -41,7 +42,7 @@ function getFilePathPrefix(files) { return commonPathPrefix(files); } -class Api extends Emittery { +export default class Api extends Emittery { constructor(options) { super(); @@ -233,7 +234,7 @@ class Api extends Emittery { const worker = fork(file, options, apiOptions.nodeArguments); runStatus.observeWorker(worker, file, {selectingLines: lineNumbers.length > 0}); - deregisteredSharedWorkers.push(sharedWorkers.observeWorkerProcess(worker, runStatus)); + deregisteredSharedWorkers.push(observeWorkerProcess(worker, runStatus)); pendingWorkers.add(worker); worker.promise.then(() => { @@ -282,5 +283,3 @@ class Api extends Emittery { return cacheDir; } } - -module.exports = Api; diff --git a/lib/assert.js b/lib/assert.js index f0e9b5c2e..83ee3f62d 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -1,10 +1,10 @@ -'use strict'; -const concordance = require('concordance'); -const isError = require('is-error'); -const isPromise = require('is-promise'); -const concordanceOptions = require('./concordance-options').default; -const {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} = require('./like-selector'); -const snapshotManager = require('./snapshot-manager'); +import concordance from 'concordance'; +import isError from 'is-error'; +import isPromise from 'is-promise'; + +import concordanceOptions from './concordance-options.js'; +import {CIRCULAR_SELECTOR, isLikeSelector, selectComparable} from './like-selector.js'; +import {SnapshotError, VersionMismatchError} from './snapshot-manager.js'; function formatDescriptorDiff(actualDescriptor, expectedDescriptor, options) { options = {...options, ...concordanceOptions}; @@ -35,7 +35,7 @@ const notImplemented = () => { throw new Error('not implemented'); }; -class AssertionError extends Error { +export class AssertionError extends Error { constructor(options) { super(options.message || ''); this.name = 'AssertionError'; @@ -58,9 +58,8 @@ class AssertionError extends Error { this.savedError = options.savedError ? options.savedError : getErrorWithLongStackTrace(); } } -exports.AssertionError = AssertionError; -function checkAssertionMessage(assertion, message) { +export function checkAssertionMessage(assertion, message) { if (typeof message === 'undefined' || typeof message === 'string') { return true; } @@ -73,8 +72,6 @@ function checkAssertionMessage(assertion, message) { }); } -exports.checkAssertionMessage = checkAssertionMessage; - function getErrorWithLongStackTrace() { const limitBefore = Error.stackTraceLimit; Error.stackTraceLimit = Number.POSITIVE_INFINITY; @@ -254,7 +251,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s } } -class Assertions { +export class Assertions { constructor({ pass = notImplemented, pending = notImplemented, @@ -756,12 +753,12 @@ class Assertions { try { result = compareWithSnapshot({expected, message}); } catch (error) { - if (!(error instanceof snapshotManager.SnapshotError)) { + if (!(error instanceof SnapshotError)) { throw error; } const improperUsage = {name: error.name, snapPath: error.snapPath}; - if (error instanceof snapshotManager.VersionMismatchError) { + if (error instanceof VersionMismatchError) { improperUsage.snapVersion = error.snapVersion; improperUsage.expectedVersion = error.expectedVersion; } @@ -990,4 +987,3 @@ class Assertions { } } } -exports.Assertions = Assertions; diff --git a/lib/chalk.js b/lib/chalk.js index 36a2956ca..78cc64d84 100644 --- a/lib/chalk.js +++ b/lib/chalk.js @@ -1,20 +1,16 @@ -'use strict'; -const chalk = require('chalk'); +import chalk from 'chalk'; -let ctx = null; -exports.get = () => { - if (!ctx) { - throw new Error('Chalk has not yet been configured'); - } +let instance = new chalk.Instance(); +export default instance; - return ctx; -}; +export {instance as chalk}; -exports.set = options => { - if (ctx) { +let configured = false; +export function set(options) { + if (configured) { throw new Error('Chalk has already been configured'); } - ctx = new chalk.Instance(options); - return ctx; -}; + configured = true; + instance = new chalk.Instance(options); +} diff --git a/lib/cli.js b/lib/cli.js index 7c3a9cd70..abb87126f 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,16 +1,34 @@ -'use strict'; -const path = require('path'); -const del = require('del'); -const updateNotifier = require('update-notifier'); -const figures = require('figures'); -const arrify = require('arrify'); -const yargs = require('yargs'); -const readPkg = require('read-pkg'); -const isCi = require('./is-ci'); -const {loadConfig} = require('./load-config'); +import {createRequire} from 'module'; +import path from 'path'; + +import arrify from 'arrify'; +import ciParallelVars from 'ci-parallel-vars'; +import del from 'del'; +import figures from 'figures'; +import readPkg from 'read-pkg'; +import updateNotifier from 'update-notifier'; + +import Api from './api.js'; +import {chalk} from './chalk.js'; +import validateEnvironmentVariables from './environment-variables.js'; +import normalizeExtensions from './extensions.js'; +import {normalizeGlobs, normalizePattern} from './globs.js'; +import {controlFlow} from './ipc-flow-control.cjs'; +import isCi from './is-ci.js'; +import {splitPatternAndLineNumbers} from './line-numbers.js'; +import {loadConfig} from './load-config.js'; +import normalizeModuleTypes from './module-types.js'; +import normalizeNodeArguments from './node-arguments.js'; +import avaPackage from './pkg.cjs'; +import providerManager from './provider-manager.js'; +import DefaultReporter from './reporters/default.js'; +import TapReporter from './reporters/tap.js'; +import Watcher from './watcher.js'; + +const yargs = createRequire(import.meta.url)('yargs'); // FIXME: Use ESM function exit(message) { - console.error(`\n ${require('./chalk').get().red(figures.cross)} ${message}`); + console.error(`\n ${chalk.red(figures.cross)} ${message}`); process.exit(1); // eslint-disable-line unicorn/no-process-exit } @@ -83,7 +101,7 @@ const FLAGS = { } }; -exports.run = async () => { // eslint-disable-line complexity +export default async () => { // eslint-disable-line complexity let conf = {}; let confError = null; try { @@ -96,7 +114,13 @@ exports.run = async () => { // eslint-disable-line complexity // Enter debug mode if the main process is being inspected. This assumes the // worker processes are automatically inspected, too. It is not necessary to // run AVA with the debug command, though it's allowed. - const activeInspector = require('inspector').url() !== undefined; // eslint-disable-line node/no-unsupported-features/node-builtins + let activeInspector = false; + try { + const {default: inspector} = await import('inspector'); + + activeInspector = inspector.url() !== undefined; + } catch {} + let debug = activeInspector ? { active: true, @@ -207,8 +231,9 @@ exports.run = async () => { // eslint-disable-line complexity } } - const chalkOptions = {level: combined.color === false ? 0 : require('chalk').level}; - const chalk = require('./chalk').set(chalkOptions); + const chalkOptions = {level: combined.color === false ? 0 : (await import('chalk')).level}; + const {set: setChalk} = await import('./chalk.js'); + setChalk(chalkOptions); if (confError) { if (confError.parent) { @@ -218,7 +243,7 @@ exports.run = async () => { // eslint-disable-line complexity } } - updateNotifier({pkg: require('../package.json')}).notify(); + updateNotifier({pkg: avaPackage}).notify(); const {nonSemVerExperiments: experiments, projectDir} = conf; if (resetCache) { @@ -285,19 +310,6 @@ exports.run = async () => { // eslint-disable-line complexity exit('’sources’ has been removed. Use ’ignoredByWatcher’ to provide glob patterns of files that the watcher should ignore.'); } - const ciParallelVars = require('ci-parallel-vars'); - const Api = require('./api'); - const DefaultReporter = require('./reporters/default'); - const TapReporter = require('./reporters/tap'); - const Watcher = require('./watcher'); - const normalizeExtensions = require('./extensions'); - const normalizeModuleTypes = require('./module-types'); - const {normalizeGlobs, normalizePattern} = require('./globs'); - const normalizeNodeArguments = require('./node-arguments'); - const validateEnvironmentVariables = require('./environment-variables'); - const {splitPatternAndLineNumbers} = require('./line-numbers'); - const providerManager = require('./provider-manager'); - let pkg; try { pkg = readPkg.sync({cwd: projectDir}); @@ -312,7 +324,7 @@ exports.run = async () => { // eslint-disable-line complexity const providers = []; if (Reflect.has(conf, 'babel')) { try { - const {level, main} = providerManager.babel(projectDir); + const {level, main} = await providerManager.babel(projectDir); providers.push({ level, main: main({config: conf.babel}), @@ -325,7 +337,7 @@ exports.run = async () => { // eslint-disable-line complexity if (Reflect.has(conf, 'typescript')) { try { - const {level, main} = providerManager.typescript(projectDir); + const {level, main} = await providerManager.typescript(projectDir); providers.push({ level, main: main({config: conf.typescript}), @@ -415,10 +427,12 @@ exports.run = async () => { // eslint-disable-line complexity }); const reporter = combined.tap && !combined.watch && debug === null ? new TapReporter({ + extensions: globs.extensions, projectDir, reportStream: process.stdout, stdStream: process.stderr }) : new DefaultReporter({ + extensions: globs.extensions, projectDir, reportStream: process.stdout, stdStream: process.stderr, @@ -430,7 +444,6 @@ exports.run = async () => { // eslint-disable-line complexity reporter.startRun(plan); if (process.env.AVA_EMIT_RUN_STATUS_OVER_IPC === 'I\'ll find a payphone baby / Take some time to talk to you') { - const {controlFlow} = require('./ipc-flow-control'); const bufferedSend = controlFlow(process); plan.status.on('stateChange', evt => { diff --git a/lib/code-excerpt.js b/lib/code-excerpt.js index c8f81d201..391bb621e 100644 --- a/lib/code-excerpt.js +++ b/lib/code-excerpt.js @@ -1,14 +1,15 @@ -'use strict'; -const fs = require('fs'); -const equalLength = require('equal-length'); -const codeExcerpt = require('code-excerpt'); -const truncate = require('cli-truncate'); -const chalk = require('./chalk').get(); +import fs from 'fs'; + +import truncate from 'cli-truncate'; +import codeExcerpt from 'code-excerpt'; +import equalLength from 'equal-length'; + +import {chalk} from './chalk.js'; const formatLineNumber = (lineNumber, maxLineNumber) => ' '.repeat(Math.max(0, String(maxLineNumber).length - String(lineNumber).length)) + lineNumber; -module.exports = (source, options = {}) => { +export default (source, options = {}) => { if (!source.isWithinProject || source.isDependency) { return null; } @@ -18,7 +19,7 @@ module.exports = (source, options = {}) => { let contents; try { - contents = fs.readFileSync(file, 'utf8'); + contents = fs.readFileSync(new URL(file), 'utf8'); } catch { return null; } diff --git a/lib/concordance-options.js b/lib/concordance-options.js index 1e0877ef7..9de15399d 100644 --- a/lib/concordance-options.js +++ b/lib/concordance-options.js @@ -1,9 +1,10 @@ -'use strict'; -const util = require('util'); // eslint-disable-line unicorn/import-style -const ansiStyles = require('ansi-styles'); -const stripAnsi = require('strip-ansi'); -const cloneDeepWith = require('lodash/cloneDeepWith'); -const chalk = require('./chalk').get(); +import {inspect} from 'util'; + +import ansiStyles from 'ansi-styles'; +import cloneDeepWith from 'lodash/cloneDeepWith.js'; +import stripAnsi from 'strip-ansi'; + +import {chalk} from './chalk.js'; const forceColor = new chalk.Instance({level: Math.max(chalk.level, 1)}); @@ -92,12 +93,12 @@ const plainTheme = cloneDeepWith(colorTheme, value => { const theme = chalk.level > 0 ? colorTheme : plainTheme; -exports.default = { +export default { // Use Node's object inspection depth, clamped to a minimum of 3 get maxDepth() { - return Math.max(3, util.inspect.defaultOptions.depth); + return Math.max(3, inspect.defaultOptions.depth); }, theme }; -exports.snapshotManager = {theme: plainTheme}; +export const snapshotManager = {theme: plainTheme}; diff --git a/lib/context-ref.js b/lib/context-ref.js index b0b703e99..0504066a3 100644 --- a/lib/context-ref.js +++ b/lib/context-ref.js @@ -1,7 +1,6 @@ -'use strict'; -const clone = require('lodash/clone'); +import clone from 'lodash/clone.js'; -class ContextRef { +export default class ContextRef { constructor() { this.value = {}; } @@ -18,7 +17,6 @@ class ContextRef { return new LateBinding(this); } } -module.exports = ContextRef; class LateBinding extends ContextRef { constructor(ref) { diff --git a/lib/create-chain.js b/lib/create-chain.js index 875eac060..b4d36a912 100644 --- a/lib/create-chain.js +++ b/lib/create-chain.js @@ -1,4 +1,3 @@ -'use strict'; const chainRegistry = new WeakMap(); function startChain(name, call, defaults) { @@ -57,7 +56,7 @@ function createHookChain(hook, isAfterHook) { return hook; } -function createChain(fn, defaults, meta) { +export default function createChain(fn, defaults, meta) { // Test chaining rules: // * `serial` must come at the start // * `only` and `skip` must come at the end @@ -96,5 +95,3 @@ function createChain(fn, defaults, meta) { return root; } - -module.exports = createChain; diff --git a/lib/environment-variables.js b/lib/environment-variables.js index 2d226dfce..de2ac106c 100644 --- a/lib/environment-variables.js +++ b/lib/environment-variables.js @@ -1,5 +1,4 @@ -'use strict'; -function validateEnvironmentVariables(environmentVariables) { +export default function validateEnvironmentVariables(environmentVariables) { if (!environmentVariables) { return {}; } @@ -12,5 +11,3 @@ function validateEnvironmentVariables(environmentVariables) { return environmentVariables; } - -module.exports = validateEnvironmentVariables; diff --git a/lib/eslint-plugin-helper-worker.js b/lib/eslint-plugin-helper-worker.js index 273647bb6..4affd04ae 100644 --- a/lib/eslint-plugin-helper-worker.js +++ b/lib/eslint-plugin-helper-worker.js @@ -1,20 +1,19 @@ -'use strict'; -const v8 = require('v8'); -const {parentPort, workerData} = require('worker_threads'); +import v8 from 'v8'; +import {parentPort, workerData} from 'worker_threads'; -const {normalizeGlobs} = require('./globs'); -const normalizeExtensions = require('./extensions'); -const {loadConfig} = require('./load-config'); -const providerManager = require('./provider-manager'); +import normalizeExtensions from './extensions.js'; +import {normalizeGlobs} from './globs.js'; +import {loadConfig} from './load-config.js'; +import providerManager from './provider-manager.js'; const MAX_DATA_LENGTH_EXCLUSIVE = 100 * 1024; // Allocate 100 KiB to exchange globs. const configCache = new Map(); -const collectProviders = ({conf, projectDir}) => { +const collectProviders = async ({conf, projectDir}) => { const providers = []; if (Reflect.has(conf, 'babel')) { - const {level, main} = providerManager.babel(projectDir); + const {level, main} = await providerManager.babel(projectDir); providers.push({ level, main: main({config: conf.babel}), @@ -23,7 +22,7 @@ const collectProviders = ({conf, projectDir}) => { } if (Reflect.has(conf, 'typescript')) { - const {level, main} = providerManager.typescript(projectDir); + const {level, main} = await providerManager.typescript(projectDir); providers.push({ level, main: main({config: conf.typescript}), @@ -51,8 +50,8 @@ const buildGlobs = ({conf, providers, projectDir, overrideExtensions, overrideFi const resolveGlobs = async (projectDir, overrideExtensions, overrideFiles) => { if (!configCache.has(projectDir)) { - configCache.set(projectDir, loadConfig({resolveFrom: projectDir}).then(conf => { // eslint-disable-line promise/prefer-await-to-then - const providers = collectProviders({conf, projectDir}); + configCache.set(projectDir, loadConfig({resolveFrom: projectDir}).then(async conf => { // eslint-disable-line promise/prefer-await-to-then + const providers = await collectProviders({conf, projectDir}); return {conf, providers}; })); } diff --git a/lib/extensions.js b/lib/extensions.js index 8ee05c3f7..6c7bb6bc3 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -1,4 +1,4 @@ -module.exports = (configuredExtensions, providers = []) => { +export default (configuredExtensions, providers = []) => { // Combine all extensions possible for testing. Remove duplicate extensions. const duplicates = new Set(); const seen = new Set(); diff --git a/lib/fork.js b/lib/fork.js index bc3648d53..ef2ecafec 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -1,10 +1,15 @@ -'use strict'; -const {Worker} = require('worker_threads'); -const childProcess = require('child_process'); -const Emittery = require('emittery'); -const {controlFlow} = require('./ipc-flow-control'); +import childProcess from 'child_process'; +import {fileURLToPath} from 'url'; +import {Worker} from 'worker_threads'; -const WORKER_PATH = require.resolve('./worker/base.js'); +import Emittery from 'emittery'; + +import {controlFlow} from './ipc-flow-control.cjs'; + +let workerPath = new URL('worker/base.js', import.meta.url); +export function _testOnlyReplaceWorkerPath(replacement) { + workerPath = replacement; +} let forkCounter = 0; @@ -13,7 +18,7 @@ const createWorker = (options, execArgv) => { let postMessage; let close; if (options.workerThreads) { - worker = new Worker(WORKER_PATH, { + worker = new Worker(workerPath, { argv: options.workerArgv, env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables}, execArgv, @@ -34,7 +39,7 @@ const createWorker = (options, execArgv) => { } }; } else { - worker = childProcess.fork(WORKER_PATH, options.workerArgv, { + worker = childProcess.fork(fileURLToPath(workerPath), options.workerArgv, { cwd: options.projectDir, silent: true, env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables}, @@ -51,7 +56,7 @@ const createWorker = (options, execArgv) => { }; }; -module.exports = (file, options, execArgv = process.execArgv) => { +export default (file, options, execArgv = process.execArgv) => { // TODO: this can be changed to use `threadId` when using worker_threads const forkId = `fork/${++forkCounter}`; diff --git a/lib/glob-helpers.cjs b/lib/glob-helpers.cjs new file mode 100644 index 000000000..7f0329658 --- /dev/null +++ b/lib/glob-helpers.cjs @@ -0,0 +1,136 @@ +'use strict'; +const path = require('path'); + +const ignoreByDefault = require('ignore-by-default'); +const picomatch = require('picomatch'); +const slash = require('slash'); + +const defaultIgnorePatterns = [...ignoreByDefault.directories(), '**/node_modules']; +exports.defaultIgnorePatterns = defaultIgnorePatterns; + +const defaultPicomatchIgnorePatterns = [ + ...defaultIgnorePatterns, + // Unlike globby(), picomatch needs a complete pattern when ignoring directories. + ...defaultIgnorePatterns.map(pattern => `${pattern}/**/*`) +]; + +const defaultMatchNoIgnore = picomatch(defaultPicomatchIgnorePatterns); + +const matchingCache = new WeakMap(); +const processMatchingPatterns = input => { + let result = matchingCache.get(input); + if (!result) { + const ignore = [...defaultPicomatchIgnorePatterns]; + const patterns = input.filter(pattern => { + if (pattern.startsWith('!')) { + // Unlike globby(), picomatch needs a complete pattern when ignoring directories. + ignore.push(pattern.slice(1), `${pattern.slice(1)}/**/*`); + return false; + } + + return true; + }); + + result = { + match: picomatch(patterns, {ignore}), + matchNoIgnore: picomatch(patterns) + }; + matchingCache.set(input, result); + } + + return result; +}; + +const matchesIgnorePatterns = (file, patterns) => { + const {matchNoIgnore} = processMatchingPatterns(patterns); + return matchNoIgnore(file) || defaultMatchNoIgnore(file); +}; + +function classify(file, {cwd, extensions, filePatterns, ignoredByWatcherPatterns}) { + file = normalizeFileForMatching(cwd, file); + return { + isIgnoredByWatcher: matchesIgnorePatterns(file, ignoredByWatcherPatterns), + isTest: hasExtension(extensions, file) && !isHelperish(file) && filePatterns.length > 0 && matches(file, filePatterns) + }; +} + +exports.classify = classify; + +const hasExtension = (extensions, file) => extensions.includes(path.extname(file).slice(1)); + +exports.hasExtension = hasExtension; + +function isHelperish(file) { // Assume file has been normalized already. + // File names starting with an underscore are deemed "helpers". + if (path.basename(file).startsWith('_')) { + return true; + } + + // This function assumes the file has been normalized. If it couldn't be, + // don't check if it's got a parent directory that starts with an underscore. + // Deem it not a "helper". + if (path.isAbsolute(file)) { + return false; + } + + // If the file has a parent directory that starts with only a single + // underscore, it's deemed a "helper". + return path.dirname(file).split('/').some(dir => /^_(?:$|[^_])/.test(dir)); +} + +exports.isHelperish = isHelperish; + +function matches(file, patterns) { + const {match} = processMatchingPatterns(patterns); + return match(file); +} + +exports.matches = matches; + +function normalizeFileForMatching(cwd, file) { + if (process.platform === 'win32') { + cwd = slash(cwd); + file = slash(file); + } + + if (!cwd) { // TODO: Ensure tests provide an actual value. + return file; + } + + // TODO: If `file` is outside `cwd` we can't normalize it. Need to figure + // out if that's a real-world scenario, but we may have to ensure the file + // isn't even selected. + if (!file.startsWith(cwd)) { + return file; + } + + // Assume `cwd` does *not* end in a slash. + return file.slice(cwd.length + 1); +} + +exports.normalizeFileForMatching = normalizeFileForMatching; + +function normalizePattern(pattern) { + // Always use `/` in patterns, harmonizing matching across platforms + if (process.platform === 'win32') { + pattern = slash(pattern); + } + + if (pattern.startsWith('./')) { + return pattern.slice(2); + } + + if (pattern.startsWith('!./')) { + return `!${pattern.slice(3)}`; + } + + return pattern; +} + +exports.normalizePattern = normalizePattern; + +function normalizePatterns(patterns) { + return patterns.map(pattern => normalizePattern(pattern)); +} + +exports.normalizePatterns = normalizePatterns; diff --git a/lib/globs.js b/lib/globs.js index 2e03d312f..132c7424a 100644 --- a/lib/globs.js +++ b/lib/globs.js @@ -1,19 +1,29 @@ -'use strict'; -const path = require('path'); -const globby = require('globby'); -const ignoreByDefault = require('ignore-by-default'); -const picomatch = require('picomatch'); -const slash = require('slash'); -const providerManager = require('./provider-manager'); - -const defaultIgnorePatterns = [...ignoreByDefault.directories(), '**/node_modules']; -const defaultPicomatchIgnorePatterns = [ - ...defaultIgnorePatterns, - // Unlike globby(), picomatch needs a complete pattern when ignoring directories. - ...defaultIgnorePatterns.map(pattern => `${pattern}/**/*`) -]; - -const defaultMatchNoIgnore = picomatch(defaultPicomatchIgnorePatterns); +import path from 'path'; + +import globby from 'globby'; + +import { + classify, + defaultIgnorePatterns, + hasExtension, + isHelperish, + matches, + normalizeFileForMatching, + normalizePattern, + normalizePatterns +} from './glob-helpers.cjs'; +import providerManager from './provider-manager.js'; + +export { + classify, + defaultIgnorePatterns, + hasExtension, + isHelperish, + matches, + normalizeFileForMatching, + normalizePattern, + normalizePatterns +}; const defaultIgnoredByWatcherPatterns = [ '**/*.snap.md', // No need to rerun tests when the Markdown files change. @@ -23,32 +33,7 @@ const defaultIgnoredByWatcherPatterns = [ const buildExtensionPattern = extensions => extensions.length === 1 ? extensions[0] : `{${extensions.join(',')}}`; -function normalizePattern(pattern) { - // Always use `/` in patterns, harmonizing matching across platforms - if (process.platform === 'win32') { - pattern = slash(pattern); - } - - if (pattern.startsWith('./')) { - return pattern.slice(2); - } - - if (pattern.startsWith('!./')) { - return `!${pattern.slice(3)}`; - } - - return pattern; -} - -exports.normalizePattern = normalizePattern; - -function normalizePatterns(patterns) { - return patterns.map(pattern => normalizePattern(pattern)); -} - -exports.normalizePatterns = normalizePatterns; - -function normalizeGlobs({extensions, files: filePatterns, ignoredByWatcher: ignoredByWatcherPatterns, providers}) { +export function normalizeGlobs({extensions, files: filePatterns, ignoredByWatcher: ignoredByWatcherPatterns, providers}) { if (filePatterns !== undefined && (!Array.isArray(filePatterns) || filePatterns.length === 0)) { throw new Error('The ’files’ configuration must be an array containing glob patterns.'); } @@ -93,12 +78,6 @@ function normalizeGlobs({extensions, files: filePatterns, ignoredByWatcher: igno return {extensions, filePatterns, ignoredByWatcherPatterns}; } -exports.normalizeGlobs = normalizeGlobs; - -const hasExtension = (extensions, file) => extensions.includes(path.extname(file).slice(1)); - -exports.hasExtension = hasExtension; - const globFiles = async (cwd, patterns) => { const files = await globby(patterns, { // Globs should work relative to the cwd value only (this should be the @@ -125,119 +104,21 @@ const globFiles = async (cwd, patterns) => { return files.map(file => path.join(cwd, file)); }; -async function findFiles({cwd, extensions, filePatterns}) { +export async function findFiles({cwd, extensions, filePatterns}) { return (await globFiles(cwd, filePatterns)).filter(file => hasExtension(extensions, file)); } -exports.findFiles = findFiles; - -async function findTests({cwd, extensions, filePatterns}) { +export async function findTests({cwd, extensions, filePatterns}) { return (await findFiles({cwd, extensions, filePatterns})).filter(file => !path.basename(file).startsWith('_')); } -exports.findTests = findTests; - -function getChokidarIgnorePatterns({ignoredByWatcherPatterns}) { +export function getChokidarIgnorePatterns({ignoredByWatcherPatterns}) { return [ ...defaultIgnorePatterns.map(pattern => `${pattern}/**/*`), ...ignoredByWatcherPatterns.filter(pattern => !pattern.startsWith('!')) ]; } -exports.getChokidarIgnorePatterns = getChokidarIgnorePatterns; - -const matchingCache = new WeakMap(); -const processMatchingPatterns = input => { - let result = matchingCache.get(input); - if (!result) { - const ignore = [...defaultPicomatchIgnorePatterns]; - const patterns = input.filter(pattern => { - if (pattern.startsWith('!')) { - // Unlike globby(), picomatch needs a complete pattern when ignoring directories. - ignore.push(pattern.slice(1), `${pattern.slice(1)}/**/*`); - return false; - } - - return true; - }); - - result = { - match: picomatch(patterns, {ignore}), - matchNoIgnore: picomatch(patterns) - }; - matchingCache.set(input, result); - } - - return result; -}; - -function matches(file, patterns) { - const {match} = processMatchingPatterns(patterns); - return match(file); -} - -exports.matches = matches; - -const matchesIgnorePatterns = (file, patterns) => { - const {matchNoIgnore} = processMatchingPatterns(patterns); - return matchNoIgnore(file) || defaultMatchNoIgnore(file); -}; - -function normalizeFileForMatching(cwd, file) { - if (process.platform === 'win32') { - cwd = slash(cwd); - file = slash(file); - } - - if (!cwd) { // TODO: Ensure tests provide an actual value. - return file; - } - - // TODO: If `file` is outside `cwd` we can't normalize it. Need to figure - // out if that's a real-world scenario, but we may have to ensure the file - // isn't even selected. - if (!file.startsWith(cwd)) { - return file; - } - - // Assume `cwd` does *not* end in a slash. - return file.slice(cwd.length + 1); -} - -exports.normalizeFileForMatching = normalizeFileForMatching; - -function isHelperish(file) { // Assume file has been normalized already. - // File names starting with an underscore are deemed "helpers". - if (path.basename(file).startsWith('_')) { - return true; - } - - // This function assumes the file has been normalized. If it couldn't be, - // don't check if it's got a parent directory that starts with an underscore. - // Deem it not a "helper". - if (path.isAbsolute(file)) { - return false; - } - - // If the file has a parent directory that starts with only a single - // underscore, it's deemed a "helper". - return path.dirname(file).split('/').some(dir => /^_(?:$|[^_])/.test(dir)); -} - -exports.isHelperish = isHelperish; - -function classify(file, {cwd, extensions, filePatterns, ignoredByWatcherPatterns}) { - file = normalizeFileForMatching(cwd, file); - return { - isIgnoredByWatcher: matchesIgnorePatterns(file, ignoredByWatcherPatterns), - isTest: hasExtension(extensions, file) && !isHelperish(file) && filePatterns.length > 0 && matches(file, filePatterns) - }; -} - -exports.classify = classify; - -function applyTestFileFilter({cwd, filter, testFiles}) { +export function applyTestFileFilter({cwd, filter, testFiles}) { return testFiles.filter(file => matches(normalizeFileForMatching(cwd, file), filter)); } - -exports.applyTestFileFilter = applyTestFileFilter; diff --git a/lib/ipc-flow-control.js b/lib/ipc-flow-control.cjs similarity index 98% rename from lib/ipc-flow-control.js rename to lib/ipc-flow-control.cjs index 52583c690..7a7d5d0e9 100644 --- a/lib/ipc-flow-control.js +++ b/lib/ipc-flow-control.cjs @@ -1,3 +1,4 @@ +'use strict'; function controlFlow(channel) { let errored = false; let deliverImmediately = true; diff --git a/lib/is-ci.js b/lib/is-ci.js index 227e7e183..65e3c2d77 100644 --- a/lib/is-ci.js +++ b/lib/is-ci.js @@ -1,5 +1,5 @@ -const info = require('ci-info'); +import info from 'ci-info'; const {AVA_FORCE_CI} = process.env; -module.exports = AVA_FORCE_CI === 'not-ci' ? false : AVA_FORCE_CI === 'ci' || info.isCI; +export default AVA_FORCE_CI === 'not-ci' ? false : AVA_FORCE_CI === 'ci' || info.isCI; diff --git a/lib/like-selector.js b/lib/like-selector.js index fc720a59a..22e48bb8f 100644 --- a/lib/like-selector.js +++ b/lib/like-selector.js @@ -1,17 +1,13 @@ -'use strict'; -function isLikeSelector(selector) { +export function isLikeSelector(selector) { return selector !== null && typeof selector === 'object' && Reflect.getPrototypeOf(selector) === Object.prototype && Reflect.ownKeys(selector).length > 0; } -exports.isLikeSelector = isLikeSelector; +export const CIRCULAR_SELECTOR = new Error('Encountered a circular selector'); -const CIRCULAR_SELECTOR = new Error('Encountered a circular selector'); -exports.CIRCULAR_SELECTOR = CIRCULAR_SELECTOR; - -function selectComparable(lhs, selector, circular = new Set()) { +export function selectComparable(lhs, selector, circular = new Set()) { if (circular.has(selector)) { throw CIRCULAR_SELECTOR; } @@ -33,5 +29,3 @@ function selectComparable(lhs, selector, circular = new Set()) { return comparable; } - -exports.selectComparable = selectComparable; diff --git a/lib/line-numbers.js b/lib/line-numbers.js index e9e79ee40..1b70e434d 100644 --- a/lib/line-numbers.js +++ b/lib/line-numbers.js @@ -1,7 +1,5 @@ -'use strict'; - -const picomatch = require('picomatch'); -const flatten = require('lodash/flatten'); +import flatten from 'lodash/flatten.js'; +import picomatch from 'picomatch'; const NUMBER_REGEX = /^\d+$/; const RANGE_REGEX = /^(?\d+)-(?\d+)$/; @@ -37,7 +35,7 @@ const parseLineNumbers = suffix => sortNumbersAscending(distinctArray(flatten( }) ))); -function splitPatternAndLineNumbers(pattern) { +export function splitPatternAndLineNumbers(pattern) { const parts = pattern.split(DELIMITER); if (parts.length === 1) { return {pattern, lineNumbers: null}; @@ -51,14 +49,10 @@ function splitPatternAndLineNumbers(pattern) { return {pattern: parts.join(DELIMITER), lineNumbers: parseLineNumbers(suffix)}; } -exports.splitPatternAndLineNumbers = splitPatternAndLineNumbers; - -function getApplicableLineNumbers(normalizedFilePath, filter) { +export function getApplicableLineNumbers(normalizedFilePath, filter) { return sortNumbersAscending(distinctArray(flatten( filter .filter(({pattern, lineNumbers}) => lineNumbers && picomatch.isMatch(normalizedFilePath, pattern)) .map(({lineNumbers}) => lineNumbers) ))); } - -exports.getApplicableLineNumbers = getApplicableLineNumbers; diff --git a/lib/load-config.js b/lib/load-config.js index 0b5b2d156..618ccb7ed 100644 --- a/lib/load-config.js +++ b/lib/load-config.js @@ -1,10 +1,10 @@ -'use strict'; -const fs = require('fs'); -const path = require('path'); -const url = require('url'); +import fs from 'fs'; +import {createRequire} from 'module'; +import path from 'path'; +import url from 'url'; -const {isPlainObject} = require('is-plain-object'); -const pkgConf = require('pkg-conf'); +import {isPlainObject} from 'is-plain-object'; +import pkgConf from 'pkg-conf'; const NO_SUCH_FILE = Symbol('no ava.config.js file'); const MISSING_DEFAULT_EXPORT = Symbol('missing default export'); @@ -13,7 +13,7 @@ const EXPERIMENTS = new Set([ ]); const importConfig = async ({configFile, fileForErrorMessage}) => { - const {default: config = MISSING_DEFAULT_EXPORT} = await import(url.pathToFileURL(configFile)); // eslint-disable-line node/no-unsupported-features/es-syntax + const {default: config = MISSING_DEFAULT_EXPORT} = await import(url.pathToFileURL(configFile)); if (config === MISSING_DEFAULT_EXPORT) { throw new Error(`${fileForErrorMessage} must have a default export`); } @@ -41,6 +41,7 @@ const loadCjsConfig = async ({projectDir, configFile = path.join(projectDir, 'av const fileForErrorMessage = path.relative(projectDir, configFile); try { + const require = createRequire(import.meta.url); return {config: await require(configFile), fileForErrorMessage}; } catch (error) { throw Object.assign(new Error(`Error loading ${fileForErrorMessage}`), {parent: error}); @@ -75,7 +76,7 @@ function resolveConfigFile(projectDir, configFile) { return configFile; } -async function loadConfig({configFile, resolveFrom = process.cwd(), defaults = {}} = {}) { +export async function loadConfig({configFile, resolveFrom = process.cwd(), defaults = {}} = {}) { let packageConf = await pkgConf('ava', {cwd: resolveFrom}); const filepath = pkgConf.filepath(packageConf); const projectDir = filepath === null ? resolveFrom : path.dirname(filepath); @@ -133,5 +134,3 @@ async function loadConfig({configFile, resolveFrom = process.cwd(), defaults = { return config; } - -exports.loadConfig = loadConfig; diff --git a/lib/module-types.js b/lib/module-types.js index 2c562fbad..80b2b3092 100644 --- a/lib/module-types.js +++ b/lib/module-types.js @@ -54,7 +54,7 @@ const deriveFromArray = (extensions, defaultModuleType) => { return moduleTypes; }; -module.exports = (configuredExtensions, defaultModuleType) => { +export default (configuredExtensions, defaultModuleType) => { if (configuredExtensions === undefined) { return { cjs: 'commonjs', diff --git a/lib/node-arguments.js b/lib/node-arguments.js index 0acc4d97e..deb2ad97f 100644 --- a/lib/node-arguments.js +++ b/lib/node-arguments.js @@ -1,7 +1,6 @@ -'use strict'; -const arrgv = require('arrgv'); +import arrgv from 'arrgv'; -function normalizeNodeArguments(fromConf = [], fromArgv = '') { +export default function normalizeNodeArguments(fromConf = [], fromArgv = '') { let parsedArgv = []; if (fromArgv !== '') { try { @@ -13,5 +12,3 @@ function normalizeNodeArguments(fromConf = [], fromArgv = '') { return [...process.execArgv, ...fromConf, ...parsedArgv]; } - -module.exports = normalizeNodeArguments; diff --git a/lib/now-and-timers.js b/lib/now-and-timers.cjs similarity index 100% rename from lib/now-and-timers.js rename to lib/now-and-timers.cjs diff --git a/lib/parse-test-args.js b/lib/parse-test-args.js index 5ea5f0aa4..8a0cda0c7 100644 --- a/lib/parse-test-args.js +++ b/lib/parse-test-args.js @@ -1,5 +1,4 @@ -'use strict'; -function parseTestArgs(args) { +export default function parseTestArgs(args) { const rawTitle = typeof args[0] === 'string' ? args.shift() : undefined; const receivedImplementationArray = Array.isArray(args[0]); const implementations = receivedImplementationArray ? args.shift() : args.splice(0, 1); @@ -11,5 +10,3 @@ function parseTestArgs(args) { return {args, buildTitle, implementations, rawTitle, receivedImplementationArray}; } - -module.exports = parseTestArgs; diff --git a/lib/pkg.cjs b/lib/pkg.cjs new file mode 100644 index 000000000..8adecbd96 --- /dev/null +++ b/lib/pkg.cjs @@ -0,0 +1,2 @@ +'use strict'; +module.exports = require('../package.json'); diff --git a/lib/plugin-support/shared-worker-loader.js b/lib/plugin-support/shared-worker-loader.js index 9f9f4041c..6d66ab935 100644 --- a/lib/plugin-support/shared-worker-loader.js +++ b/lib/plugin-support/shared-worker-loader.js @@ -1,6 +1,7 @@ -const {EventEmitter, on} = require('events'); -const {workerData, parentPort} = require('worker_threads'); -const pkg = require('../../package.json'); +import {EventEmitter, on} from 'events'; +import {workerData, parentPort} from 'worker_threads'; + +import pkg from '../pkg.cjs'; // Used to forward messages received over the `parentPort` and any direct ports // to test workers. Every subscription adds a listener, so do not enforce any @@ -154,21 +155,8 @@ function broadcastMessage(data) { } async function loadFactory() { - try { - const mod = require(workerData.filename); - if (typeof mod === 'function') { - return mod; - } - - return mod.default; - } catch (error) { - if (error && (error.code === 'ERR_REQUIRE_ESM' || (error.code === 'MODULE_NOT_FOUND' && workerData.filename.startsWith('file://')))) { - const {default: factory} = await import(workerData.filename); // eslint-disable-line node/no-unsupported-features/es-syntax - return factory; - } - - throw error; - } + const {default: factory} = await import(workerData.filename); + return factory; } let signalAvailable = () => { diff --git a/lib/plugin-support/shared-workers.js b/lib/plugin-support/shared-workers.js index 0236c856d..e0853856e 100644 --- a/lib/plugin-support/shared-workers.js +++ b/lib/plugin-support/shared-workers.js @@ -1,8 +1,10 @@ -const events = require('events'); -const {Worker} = require('worker_threads'); -const serializeError = require('../serialize-error'); +import events from 'events'; +import {pathToFileURL} from 'url'; +import {Worker} from 'worker_threads'; -const LOADER = require.resolve('./shared-worker-loader'); +import serializeError from '../serialize-error.js'; + +const LOADER = new URL('shared-worker-loader.js', import.meta.url); let sharedWorkerCounter = 0; const launchedWorkers = new Map(); @@ -50,7 +52,7 @@ function launchWorker(filename, initialData) { return launched; } -async function observeWorkerProcess(fork, runStatus) { +export async function observeWorkerProcess(fork, runStatus) { let registrationCount = 0; let signalDeregistered; const deregistered = new Promise(resolve => { @@ -94,7 +96,7 @@ async function observeWorkerProcess(fork, runStatus) { launched.worker.postMessage({ type: 'register-test-worker', id: fork.forkId, - file: fork.file, + file: pathToFileURL(fork.file).toString(), port }, [port]); @@ -118,5 +120,3 @@ async function observeWorkerProcess(fork, runStatus) { return deregistered; } - -exports.observeWorkerProcess = observeWorkerProcess; diff --git a/lib/provider-manager.js b/lib/provider-manager.js index 5c95c07ff..81fa8ca34 100644 --- a/lib/provider-manager.js +++ b/lib/provider-manager.js @@ -1,21 +1,19 @@ -const pkg = require('../package.json'); -const globs = require('./globs'); +import * as globs from './globs.js'; +import pkg from './pkg.cjs'; const levels = { ava3: 1, pathRewrites: 2 }; -exports.levels = levels; - const levelsByProtocol = { 'ava-3': levels.ava3, 'ava-3.2': levels.pathRewrites }; -function load(providerModule, projectDir) { +async function load(providerModule, projectDir) { const ava = {version: pkg.version}; - const makeProvider = require(providerModule); + const {default: makeProvider} = await import(providerModule); let fatal; let level; @@ -49,5 +47,12 @@ function load(providerModule, projectDir) { return {...provider, level}; } -exports.babel = projectDir => load('@ava/babel', projectDir); -exports.typescript = projectDir => load('@ava/typescript', projectDir); +export default { + levels, + async babel(projectDir) { + return load('@ava/babel', projectDir); + }, + async typescript(projectDir) { + return load('@ava/typescript', projectDir); + } +}; diff --git a/lib/reporters/beautify-stack.js b/lib/reporters/beautify-stack.js index 76c0a35a7..de8ad9def 100644 --- a/lib/reporters/beautify-stack.js +++ b/lib/reporters/beautify-stack.js @@ -1,5 +1,4 @@ -'use strict'; -const StackUtils = require('stack-utils'); +import StackUtils from 'stack-utils'; const stackUtils = new StackUtils({ ignoredPackages: [ @@ -59,7 +58,7 @@ const stackUtils = new StackUtils({ * Module.runMain (module.js:604:10) * ``` */ -module.exports = stack => { +export default stack => { if (!stack) { return []; } diff --git a/lib/reporters/colors.js b/lib/reporters/colors.js index 31d0ec912..f1f25b3fb 100644 --- a/lib/reporters/colors.js +++ b/lib/reporters/colors.js @@ -1,17 +1,40 @@ -'use strict'; -const chalk = require('../chalk').get(); +import {chalk} from '../chalk.js'; -module.exports = { - log: chalk.gray, - title: chalk.bold, - error: chalk.red, - skip: chalk.yellow, - todo: chalk.blue, - pass: chalk.green, - duration: chalk.gray.dim, - errorSource: chalk.gray, - errorStack: chalk.gray, - errorStackInternal: chalk.gray.dim, - stack: chalk.red, - information: chalk.magenta +export default { + get log() { + return chalk.gray; + }, + get title() { + return chalk.bold; + }, + get error() { + return chalk.red; + }, + get skip() { + return chalk.yellow; + }, + get todo() { + return chalk.blue; + }, + get pass() { + return chalk.green; + }, + get duration() { + return chalk.gray.dim; + }, + get errorSource() { + return chalk.gray; + }, + get errorStack() { + return chalk.gray; + }, + get errorStackInternal() { + return chalk.gray.dim; + }, + get stack() { + return chalk.red; + }, + get information() { + return chalk.magenta; + } }; diff --git a/lib/reporters/default.js b/lib/reporters/default.js index 94c1d6b83..b4fc1b608 100644 --- a/lib/reporters/default.js +++ b/lib/reporters/default.js @@ -1,25 +1,27 @@ -'use strict'; -const os = require('os'); -const path = require('path'); -const stream = require('stream'); - -const cliCursor = require('cli-cursor'); -const figures = require('figures'); -const indentString = require('indent-string'); -const ora = require('ora'); -const plur = require('plur'); -const prettyMs = require('pretty-ms'); -const trimOffNewlines = require('trim-off-newlines'); - -const chalk = require('../chalk').get(); -const codeExcerpt = require('../code-excerpt'); -const beautifyStack = require('./beautify-stack'); -const colors = require('./colors'); -const formatSerializedError = require('./format-serialized-error'); -const improperUsageMessages = require('./improper-usage-messages'); -const prefixTitle = require('./prefix-title'); - -const nodeInternals = require('stack-utils').nodeInternals(); +import os from 'os'; +import path from 'path'; +import stream from 'stream'; +import {fileURLToPath} from 'url'; + +import cliCursor from 'cli-cursor'; +import figures from 'figures'; +import indentString from 'indent-string'; +import ora from 'ora'; +import plur from 'plur'; +import prettyMs from 'pretty-ms'; +import StackUtils from 'stack-utils'; +import trimOffNewlines from 'trim-off-newlines'; + +import {chalk} from '../chalk.js'; +import codeExcerpt from '../code-excerpt.js'; + +import beautifyStack from './beautify-stack.js'; +import colors from './colors.js'; +import formatSerializedError from './format-serialized-error.js'; +import improperUsageMessage from './improper-usage-messages.js'; +import prefixTitle from './prefix-title.js'; + +const nodeInternals = StackUtils.nodeInternals(); class LineWriter extends stream.Writable { constructor(dest) { @@ -138,8 +140,9 @@ function manageCorking(stream) { }; } -class Reporter { +export default class Reporter { constructor({ + extensions, verbose, reportStream, stdStream, @@ -148,11 +151,18 @@ class Reporter { spinner, durationThreshold }) { + this.extensions = extensions; this.verbose = verbose; this.reportStream = reportStream; this.stdStream = stdStream; this.watching = watching; - this.relativeFile = file => path.relative(projectDir, file); + this.relativeFile = file => { + if (file.startsWith('file://')) { + file = fileURLToPath(file); + } + + return path.relative(projectDir, file); + }; const {decorateWriter, decorateFlushingWriter} = manageCorking(this.reportStream); this.consumeStateChange = decorateWriter(this.consumeStateChange); @@ -222,7 +232,7 @@ class Reporter { this.emptyParallelRun = plan.status.emptyParallelRun; if (this.watching || plan.files.length > 1) { - this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title); + this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title); } this.removePreviousListener = plan.status.on('stateChange', evt => { @@ -551,7 +561,7 @@ class Reporter { this.lineWriter.writeLine(); } - const message = improperUsageMessages.forError(event.err); + const message = improperUsageMessage(event.err); if (message) { this.lineWriter.writeLine(message); this.lineWriter.writeLine(); @@ -902,4 +912,3 @@ class Reporter { } } } -module.exports = Reporter; diff --git a/lib/reporters/format-serialized-error.js b/lib/reporters/format-serialized-error.js index d9cfe2659..f113c502a 100644 --- a/lib/reporters/format-serialized-error.js +++ b/lib/reporters/format-serialized-error.js @@ -1,8 +1,8 @@ -'use strict'; -const trimOffNewlines = require('trim-off-newlines'); -const chalk = require('../chalk').get(); +import trimOffNewlines from 'trim-off-newlines'; -function formatSerializedError(error) { +import {chalk} from '../chalk.js'; + +export default function formatSerializedError(error) { const printMessage = error.values.length === 0 ? Boolean(error.message) : !error.values[0].label.startsWith(error.message); @@ -23,5 +23,3 @@ function formatSerializedError(error) { formatted = trimOffNewlines(formatted); return {formatted, printMessage}; } - -module.exports = formatSerializedError; diff --git a/lib/reporters/improper-usage-messages.js b/lib/reporters/improper-usage-messages.js index 6cc3276c3..8f6f3e138 100644 --- a/lib/reporters/improper-usage-messages.js +++ b/lib/reporters/improper-usage-messages.js @@ -1,8 +1,7 @@ -'use strict'; -const chalk = require('../chalk').get(); -const pkg = require('../../package.json'); +import {chalk} from '../chalk.js'; +import pkg from '../pkg.cjs'; -exports.forError = error => { +export default function buildMessage(error) { if (!error.improperUsage) { return null; } @@ -52,4 +51,4 @@ ${upgradeMessage}`; } return null; -}; +} diff --git a/lib/reporters/prefix-title.js b/lib/reporters/prefix-title.js index 83636ef02..bc5df4ed1 100644 --- a/lib/reporters/prefix-title.js +++ b/lib/reporters/prefix-title.js @@ -1,21 +1,22 @@ -'use strict'; -const path = require('path'); -const figures = require('figures'); -const chalk = require('../chalk').get(); +import path from 'path'; -const SEPERATOR = ' ' + chalk.gray.dim(figures.pointerSmall) + ' '; +import figures from 'figures'; -module.exports = (base, file, title) => { +import {chalk} from '../chalk.js'; + +const SEPARATOR = ' ' + chalk.gray.dim(figures.pointerSmall) + ' '; + +export default (extensions, base, file, title) => { const prefix = file // Only replace base if it is found at the start of the path .replace(base, (match, offset) => offset === 0 ? '' : match) .replace(/\.spec/, '') .replace(/\.test/, '') .replace(/test-/g, '') - .replace(/\.js$/, '') + .replace(new RegExp(`.(${extensions.join('|')})$`), '') .split(path.sep) .filter(p => p !== '__tests__') - .join(SEPERATOR); + .join(SEPARATOR); - return prefix + SEPERATOR + title; + return prefix + SEPARATOR + title; }; diff --git a/lib/reporters/tap.js b/lib/reporters/tap.js index 8520412dd..47871366f 100644 --- a/lib/reporters/tap.js +++ b/lib/reporters/tap.js @@ -1,14 +1,13 @@ -'use strict'; -const os = require('os'); -const path = require('path'); +import os from 'os'; +import path from 'path'; -const plur = require('plur'); -const stripAnsi = require('strip-ansi'); -const supertap = require('supertap'); -const indentString = require('indent-string'); +import indentString from 'indent-string'; +import plur from 'plur'; +import stripAnsi from 'strip-ansi'; +import supertap from 'supertap'; -const beautifyStack = require('./beautify-stack'); -const prefixTitle = require('./prefix-title'); +import beautifyStack from './beautify-stack.js'; +import prefixTitle from './prefix-title.js'; function dumpError(error) { const object = {...error.object}; @@ -46,10 +45,11 @@ function dumpError(error) { return object; } -class TapReporter { +export default class TapReporter { constructor(options) { this.i = 0; + this.extensions = options.extensions; this.stdStream = options.stdStream; this.reportStream = options.reportStream; @@ -62,7 +62,7 @@ class TapReporter { startRun(plan) { if (plan.files.length > 1) { - this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title); + this.prefixTitle = (testFile, title) => prefixTitle(this.extensions, plan.filePathPrefix, testFile, title); } plan.status.on('stateChange', evt => this.consumeStateChange(evt)); @@ -213,4 +213,3 @@ class TapReporter { } } } -module.exports = TapReporter; diff --git a/lib/run-status.js b/lib/run-status.js index fbfe9f014..7ba5292ab 100644 --- a/lib/run-status.js +++ b/lib/run-status.js @@ -1,8 +1,7 @@ -'use strict'; -const Emittery = require('emittery'); -const cloneDeep = require('lodash/cloneDeep'); +import Emittery from 'emittery'; +import cloneDeep from 'lodash/cloneDeep.js'; -class RunStatus extends Emittery { +export default class RunStatus extends Emittery { constructor(files, parallelRuns) { super(); @@ -199,5 +198,3 @@ class RunStatus extends Emittery { return [...this.stats.byFile].filter(statByFile => statByFile[1].failedTests).map(statByFile => statByFile[0]); } } - -module.exports = RunStatus; diff --git a/lib/runner.js b/lib/runner.js index 5bca02c88..69af03f3a 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -1,14 +1,15 @@ -'use strict'; -const Emittery = require('emittery'); -const matcher = require('matcher'); -const ContextRef = require('./context-ref'); -const createChain = require('./create-chain'); -const parseTestArgs = require('./parse-test-args'); -const snapshotManager = require('./snapshot-manager'); -const serializeError = require('./serialize-error'); -const Runnable = require('./test'); - -class Runner extends Emittery { +import Emittery from 'emittery'; +import matcher from 'matcher'; + +import ContextRef from './context-ref.js'; +import createChain from './create-chain.js'; +import parseTestArgs from './parse-test-args.js'; +import serializeError from './serialize-error.js'; +import {load as loadSnapshots, determineSnapshotDir} from './snapshot-manager.js'; +import Runnable from './test.js'; +import {waitForReady} from './worker/state.cjs'; + +export default class Runner extends Emittery { constructor(options = {}) { super(); @@ -30,7 +31,7 @@ class Runner extends Emittery { this.boundCompareTestSnapshot = this.compareTestSnapshot.bind(this); this.boundSkipSnapshot = this.skipSnapshot.bind(this); this.interrupted = false; - this.snapshots = snapshotManager.load({ + this.snapshots = loadSnapshots({ file: this.file, fixedLocation: this.snapshotDir, projectDir: this.projectDir, @@ -53,7 +54,7 @@ class Runner extends Emittery { serial: [], todo: [] }; - this.waitForReady = []; + this.waitForReady = waitForReady; const uniqueTestTitles = new Set(); this.registerUniqueTitle = title => { @@ -71,7 +72,7 @@ class Runner extends Emittery { file: options.file, get snapshotDirectory() { const {file, snapshotDir: fixedLocation, projectDir} = options; - return snapshotManager.determineSnapshotDir({file, fixedLocation, projectDir}); + return determineSnapshotDir({file, fixedLocation, projectDir}); } }); this.chain = createChain((metadata, testArgs) => { // eslint-disable-line complexity @@ -537,5 +538,3 @@ class Runner extends Emittery { this.interrupted = true; } } - -module.exports = Runner; diff --git a/lib/scheduler.js b/lib/scheduler.js index 37e13a6ce..61cd24d70 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -1,47 +1,51 @@ -const fs = require('fs'); -const path = require('path'); -const writeFileAtomic = require('write-file-atomic'); -const isCi = require('./is-ci'); +import fs from 'fs'; +import path from 'path'; -const FILENAME = 'failing-tests.json'; +import writeFileAtomic from 'write-file-atomic'; -module.exports.storeFailedTestFiles = (runStatus, cacheDir) => { - if (isCi || !cacheDir) { - return; - } +import isCi from './is-ci.js'; - try { - writeFileAtomic.sync(path.join(cacheDir, FILENAME), JSON.stringify(runStatus.getFailedTestFiles())); - } catch {} -}; +const FILENAME = 'failing-tests.json'; -// Order test-files, so that files with failing tests come first -module.exports.failingTestsFirst = (selectedFiles, cacheDir, cacheEnabled) => { - if (isCi || cacheEnabled === false) { - return selectedFiles; - } +export default { + storeFailedTestFiles(runStatus, cacheDir) { + if (isCi || !cacheDir) { + return; + } - const filePath = path.join(cacheDir, FILENAME); - let failedTestFiles; - try { - failedTestFiles = JSON.parse(fs.readFileSync(filePath)); - } catch { - return selectedFiles; - } + try { + writeFileAtomic.sync(path.join(cacheDir, FILENAME), JSON.stringify(runStatus.getFailedTestFiles())); + } catch {} + }, - return [...selectedFiles].sort((f, s) => { - if (failedTestFiles.includes(f) && failedTestFiles.includes(s)) { - return 0; + // Order test-files, so that files with failing tests come first + failingTestsFirst(selectedFiles, cacheDir, cacheEnabled) { + if (isCi || cacheEnabled === false) { + return selectedFiles; } - if (failedTestFiles.includes(f)) { - return -1; + const filePath = path.join(cacheDir, FILENAME); + let failedTestFiles; + try { + failedTestFiles = JSON.parse(fs.readFileSync(filePath)); + } catch { + return selectedFiles; } - if (failedTestFiles.includes(s)) { - return 1; - } + return [...selectedFiles].sort((f, s) => { + if (failedTestFiles.includes(f) && failedTestFiles.includes(s)) { + return 0; + } + + if (failedTestFiles.includes(f)) { + return -1; + } - return 0; - }); + if (failedTestFiles.includes(s)) { + return 1; + } + + return 0; + }); + } }; diff --git a/lib/serialize-error.js b/lib/serialize-error.js index 579f2f983..0f1b39a5e 100644 --- a/lib/serialize-error.js +++ b/lib/serialize-error.js @@ -1,37 +1,41 @@ -'use strict'; -const path = require('path'); -const cleanYamlObject = require('clean-yaml-object'); -const concordance = require('concordance'); -const isError = require('is-error'); -const slash = require('slash'); -const StackUtils = require('stack-utils'); -const assert = require('./assert'); -const concordanceOptions = require('./concordance-options').default; +import path from 'path'; +import {fileURLToPath, pathToFileURL} from 'url'; + +import cleanYamlObject from 'clean-yaml-object'; +import concordance from 'concordance'; +import isError from 'is-error'; +import StackUtils from 'stack-utils'; + +import {AssertionError} from './assert.js'; +import concordanceOptions from './concordance-options.js'; function isAvaAssertionError(source) { - return source instanceof assert.AssertionError; + return source instanceof AssertionError; } function filter(propertyName, isRoot) { return !isRoot || (propertyName !== 'message' && propertyName !== 'name' && propertyName !== 'stack'); } +function normalizeFile(file, ...base) { + return file.startsWith('file://') ? file : pathToFileURL(path.resolve(...base, file)).toString(); +} + const stackUtils = new StackUtils(); function extractSource(stack, testFile) { if (!stack || !testFile) { return null; } - // Normalize the test file so it matches `callSite.file`. - const relFile = path.relative(process.cwd(), testFile); - const normalizedFile = process.platform === 'win32' ? slash(relFile) : relFile; + testFile = normalizeFile(testFile); + for (const line of stack.split('\n')) { const callSite = stackUtils.parseLine(line); - if (callSite && callSite.file === normalizedFile) { + if (callSite && normalizeFile(callSite.file) === testFile) { return { isDependency: false, isWithinProject: true, - file: path.resolve(process.cwd(), callSite.file), + file: testFile, line: callSite.line }; } @@ -50,8 +54,8 @@ function buildSource(source) { // directory set to the project directory. const projectDir = process.cwd(); - const file = path.resolve(projectDir, source.file.trim()); - const rel = path.relative(projectDir, file); + const file = normalizeFile(source.file.trim(), projectDir); + const rel = path.relative(projectDir, fileURLToPath(file)); const [segment] = rel.split(path.sep); const isWithinProject = segment !== '..' && (process.platform !== 'win32' || !segment.includes(':')); @@ -141,7 +145,7 @@ function trySerializeError(error, shouldBeautifyStack, testFile) { return retval; } -function serializeError(origin, shouldBeautifyStack, error, testFile) { +export default function serializeError(origin, shouldBeautifyStack, error, testFile) { if (!isError(error)) { return { avaAssertionError: false, @@ -164,5 +168,3 @@ function serializeError(origin, shouldBeautifyStack, error, testFile) { }; } } - -module.exports = serializeError; diff --git a/lib/snapshot-manager.js b/lib/snapshot-manager.js index a64d387d6..8093e38c3 100644 --- a/lib/snapshot-manager.js +++ b/lib/snapshot-manager.js @@ -1,19 +1,17 @@ -'use strict'; +import crypto from 'crypto'; +import fs from 'fs'; +import path from 'path'; +import zlib from 'zlib'; -const crypto = require('crypto'); -const fs = require('fs'); -const path = require('path'); -const zlib = require('zlib'); +import cbor from 'cbor'; +import concordance from 'concordance'; +import convertSourceMap from 'convert-source-map'; +import indentString from 'indent-string'; +import mem from 'mem'; +import slash from 'slash'; +import writeFileAtomic from 'write-file-atomic'; -const concordance = require('concordance'); -const indentString = require('indent-string'); -const convertSourceMap = require('convert-source-map'); -const slash = require('slash'); -const writeFileAtomic = require('write-file-atomic'); -const mem = require('mem'); -const cbor = require('cbor'); - -const concordanceOptions = require('./concordance-options').snapshotManager; +import {snapshotManager as concordanceOptions} from './concordance-options.js'; // Increment if encoding layout or Concordance serialization versions change. Previous AVA versions will not be able to // decode buffers generated by a newer version, so changing this value will require a major version bump of AVA itself. @@ -30,24 +28,22 @@ const REPORT_TRAILING_NEWLINE = Buffer.from('\n', 'ascii'); const SHA_256_HASH_LENGTH = 32; -class SnapshotError extends Error { +export class SnapshotError extends Error { constructor(message, snapPath) { super(message); this.name = 'SnapshotError'; this.snapPath = snapPath; } } -exports.SnapshotError = SnapshotError; -class ChecksumError extends SnapshotError { +export class ChecksumError extends SnapshotError { constructor(snapPath) { super('Checksum mismatch', snapPath); this.name = 'ChecksumError'; } } -exports.ChecksumError = ChecksumError; -class VersionMismatchError extends SnapshotError { +export class VersionMismatchError extends SnapshotError { constructor(snapPath, version) { super('Unexpected snapshot version', snapPath); this.name = 'VersionMismatchError'; @@ -55,20 +51,18 @@ class VersionMismatchError extends SnapshotError { this.expectedVersion = VERSION; } } -exports.VersionMismatchError = VersionMismatchError; const LEGACY_SNAPSHOT_HEADER = Buffer.from('// Jest Snapshot v1'); function isLegacySnapshot(buffer) { return LEGACY_SNAPSHOT_HEADER.equals(buffer.slice(0, LEGACY_SNAPSHOT_HEADER.byteLength)); } -class LegacyError extends SnapshotError { +export class LegacyError extends SnapshotError { constructor(snapPath) { super('Legacy snapshot file', snapPath); this.name = 'LegacyError'; } } -exports.LegacyError = LegacyError; function tryRead(file) { try { @@ -392,7 +386,7 @@ const resolveSourceFile = mem(file => { return file; }); -const determineSnapshotDir = mem(({file, fixedLocation, projectDir}) => { +export const determineSnapshotDir = mem(({file, fixedLocation, projectDir}) => { const testDir = path.dirname(resolveSourceFile(file)); if (fixedLocation) { const relativeTestLocation = path.relative(projectDir, testDir); @@ -411,8 +405,6 @@ const determineSnapshotDir = mem(({file, fixedLocation, projectDir}) => { return testDir; }, {cacheKey: ([{file}]) => file}); -exports.determineSnapshotDir = determineSnapshotDir; - function determineSnapshotPaths({file, fixedLocation, projectDir}) { const dir = determineSnapshotDir({file, fixedLocation, projectDir}); const relFile = path.relative(projectDir, resolveSourceFile(file)); @@ -443,7 +435,7 @@ function cleanFile(file) { } } -function load({file, fixedLocation, projectDir, recordNewSnapshots, updating}) { +export function load({file, fixedLocation, projectDir, recordNewSnapshots, updating}) { // Keep runner unit tests that use `new Runner()` happy if (file === undefined || projectDir === undefined) { return new Manager({ @@ -494,5 +486,3 @@ function load({file, fixedLocation, projectDir, recordNewSnapshots, updating}) { error: snapshotError }); } - -exports.load = load; diff --git a/lib/test.js b/lib/test.js index e01c08d7a..f7fae4536 100644 --- a/lib/test.js +++ b/lib/test.js @@ -1,11 +1,11 @@ -'use strict'; -const concordance = require('concordance'); -const isPromise = require('is-promise'); -const plur = require('plur'); -const assert = require('./assert'); -const nowAndTimers = require('./now-and-timers'); -const parseTestArgs = require('./parse-test-args'); -const concordanceOptions = require('./concordance-options').default; +import concordance from 'concordance'; +import isPromise from 'is-promise'; +import plur from 'plur'; + +import {AssertionError, Assertions, checkAssertionMessage} from './assert.js'; +import concordanceOptions from './concordance-options.js'; +import nowAndTimers from './now-and-timers.cjs'; +import parseTestArgs from './parse-test-args.js'; function formatErrorValue(label, error) { const formatted = concordance.format(error, concordanceOptions); @@ -21,7 +21,7 @@ const captureSavedError = () => { }; const testMap = new WeakMap(); -class ExecutionContext extends assert.Assertions { +class ExecutionContext extends Assertions { constructor(test) { super({ pass: () => { @@ -194,7 +194,7 @@ class ExecutionContext extends assert.Assertions { } } -class Test { +export default class Test { constructor(options) { this.contextRef = options.contextRef; this.experiments = options.experiments || {}; @@ -411,7 +411,7 @@ class Test { } timeout(ms, message) { - const result = assert.checkAssertionMessage('timeout', message); + const result = checkAssertionMessage('timeout', message); if (result !== true) { this.saveFirstError(result); // Allow the timeout to be set even when the message is invalid. @@ -482,7 +482,7 @@ class Test { verifyPlan() { if (!this.assertError && this.planCount !== null && this.planCount !== this.assertCount) { - this.saveFirstError(new assert.AssertionError({ + this.saveFirstError(new AssertionError({ assertion: 'plan', message: `Planned for ${this.planCount} ${plur('assertion', this.planCount)}, but got ${this.assertCount}.`, operator: '===', @@ -534,7 +534,7 @@ class Test { values.push(formatErrorValue(`The following error was thrown, possibly before \`t.${pending.assertion}()\` could be called:`, error)); } - this.saveFirstError(new assert.AssertionError({ + this.saveFirstError(new AssertionError({ assertion: pending.assertion, fixedSource: {file: pending.file, line: pending.line}, improperUsage: true, @@ -591,7 +591,7 @@ class Test { const result = this.callFn(); if (!result.ok) { if (!this.detectImproperThrows(result.error)) { - this.saveFirstError(new assert.AssertionError({ + this.saveFirstError(new AssertionError({ message: 'Error thrown in test', savedError: result.error instanceof Error && result.error, values: [formatErrorValue('Error thrown in test:', result.error)] @@ -638,7 +638,7 @@ class Test { promise .catch(error => { // eslint-disable-line promise/prefer-await-to-then if (!this.detectImproperThrows(error)) { - this.saveFirstError(new assert.AssertionError({ + this.saveFirstError(new AssertionError({ message: 'Rejected promise returned by test', savedError: error instanceof Error && error, values: [formatErrorValue('Rejected promise returned by test. Reason:', error)] @@ -688,5 +688,3 @@ class Test { }; } } - -module.exports = Test; diff --git a/lib/watcher.js b/lib/watcher.js index 05386dd20..fe512eb38 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -1,12 +1,23 @@ -'use strict'; -const nodePath = require('path'); -const debug = require('debug')('ava:watcher'); -const chokidar = require('chokidar'); -const diff = require('lodash/difference'); -const flatten = require('lodash/flatten'); -const chalk = require('./chalk').get(); -const {applyTestFileFilter, classify, getChokidarIgnorePatterns} = require('./globs'); -const {levels: providerLevels} = require('./provider-manager'); +import nodePath from 'path'; + +import chokidar_ from 'chokidar'; +import createDebug from 'debug'; +import diff from 'lodash/difference.js'; +import flatten from 'lodash/flatten.js'; + +import {chalk} from './chalk.js'; +import {applyTestFileFilter, classify, getChokidarIgnorePatterns} from './globs.js'; +import providerManager from './provider-manager.js'; + +let chokidar = chokidar_; +export function _testOnlyReplaceChokidar(replacement) { + chokidar = replacement; +} + +let debug = createDebug('ava:watcher'); +export function _testOnlyReplaceDebug(replacement) { + debug = replacement('ava:watcher'); +} function rethrowAsync(error) { // Don't swallow exceptions. Note that any @@ -77,7 +88,7 @@ class TestDependency { } } -class Watcher { +export default class Watcher { constructor({api, filter = [], globs, projectDir, providers, reporter}) { this.debouncer = new Debouncer(this); @@ -88,7 +99,7 @@ class Watcher { const patternFilters = filter.map(({pattern}) => pattern); - this.providers = providers.filter(({level}) => level >= providerLevels.pathRewrites); + this.providers = providers.filter(({level}) => level >= providerManager.levels.pathRewrites); this.run = (specificFiles = [], updateSnapshots = false) => { const clearLogOnNextRun = this.clearLogOnNextRun && this.runVector > 0; if (this.runVector > 0) { @@ -443,5 +454,3 @@ class Watcher { this.run([...new Set([...addedOrChangedTests, ...flatten(testsByHelpersOrSource)])]); } } - -module.exports = Watcher; diff --git a/lib/worker/base.js b/lib/worker/base.js index e6d7a05f5..3b3eafe62 100644 --- a/lib/worker/base.js +++ b/lib/worker/base.js @@ -1,44 +1,34 @@ -'use strict'; -const {pathToFileURL} = require('url'); -const path = require('path'); -const currentlyUnhandled = require('currently-unhandled')(); -const {isRunningInThread, isRunningInChildProcess} = require('./utils'); - -// Check if the test is being run without AVA cli -if (!isRunningInChildProcess && !isRunningInThread) { - const chalk = require('chalk'); // Use default Chalk instance. - if (process.argv[1]) { - const fp = path.relative('.', process.argv[1]); - - console.log(); - console.error(`Test files must be run with the AVA CLI:\n\n ${chalk.grey.dim('$')} ${chalk.cyan('ava ' + fp)}\n`); - - process.exit(1); - } else { - throw new Error('The ’ava’ module can only be imported in test files'); - } -} +import {createRequire} from 'module'; +import {pathToFileURL} from 'url'; +import {workerData} from 'worker_threads'; + +import setUpCurrentlyUnhandled from 'currently-unhandled'; +import sourceMapSupport from 'source-map-support'; + +import {set as setChalk} from '../chalk.js'; +import nowAndTimers from '../now-and-timers.cjs'; +import providerManager from '../provider-manager.js'; +import Runner from '../runner.js'; +import serializeError from '../serialize-error.js'; -const channel = require('./channel'); +import channel from './channel.cjs'; +import dependencyTracking from './dependency-tracker.js'; +import lineNumberSelection from './line-numbers.cjs'; +import {set as setOptions} from './options.cjs'; +import {flags, refs, sharedWorkerTeardowns} from './state.cjs'; +import {isRunningInThread, isRunningInChildProcess} from './utils.cjs'; + +const currentlyUnhandled = setUpCurrentlyUnhandled(); const run = async options => { - require('./options').set(options); - require('../chalk').set(options.chalkOptions); + setOptions(options); + setChalk(options.chalkOptions); if (options.chalkOptions.level > 0) { const {stdout, stderr} = process; global.console = Object.assign(global.console, new console.Console({stdout, stderr, colorMode: true})); } - const nowAndTimers = require('../now-and-timers'); - const providerManager = require('../provider-manager'); - const Runner = require('../runner'); - const serializeError = require('../serialize-error'); - const dependencyTracking = require('./dependency-tracker'); - const lineNumberSelection = require('./line-numbers'); - - const sharedWorkerTeardowns = []; - async function exit(code) { if (!process.exitCode) { process.exitCode = code; @@ -77,6 +67,8 @@ const run = async options => { updateSnapshots: options.updateSnapshots }); + refs.runnerChain = runner.chain; + channel.peerFailed.then(() => { // eslint-disable-line promise/prefer-await-to-then runner.interrupt(); }); @@ -134,30 +126,10 @@ const run = async options => { exit(1); }); - let accessedRunner = false; - exports.getRunner = () => { - accessedRunner = true; - return runner; - }; - - exports.registerSharedWorker = (filename, initialData, teardown) => { - const {channel: sharedWorkerChannel, forceUnref, ready} = channel.registerSharedWorker(filename, initialData); - runner.waitForReady.push(ready); - sharedWorkerTeardowns.push(async () => { - try { - await teardown(); - } finally { - forceUnref(); - } - }); - return sharedWorkerChannel; - }; - // Store value to prevent required modules from modifying it. const testPath = options.file; // Install basic source map support. - const sourceMapSupport = require('source-map-support'); sourceMapSupport.install({ environment: 'node', handleUncaughtExceptions: false @@ -170,24 +142,25 @@ const run = async options => { // Install before processing options.require, so if helpers are added to the // require configuration the *compiled* helper will be loaded. const {projectDir, providerStates = []} = options; - const providers = providerStates.map(({type, state}) => { + const providers = (await Promise.all(providerStates.map(async ({type, state}) => { if (type === 'babel') { - const provider = providerManager.babel(projectDir).worker({extensionsToLoadAsModules, state}); + const provider = (await providerManager.babel(projectDir)).worker({extensionsToLoadAsModules, state}); runner.powerAssert = provider.powerAssert; return provider; } if (type === 'typescript') { - return providerManager.typescript(projectDir).worker({extensionsToLoadAsModules, state}); + return (await providerManager.typescript(projectDir)).worker({extensionsToLoadAsModules, state}); } return null; - }).filter(provider => provider !== null); + }))).filter(provider => provider !== null); + const require = createRequire(import.meta.url); const load = async ref => { for (const extension of extensionsToLoadAsModules) { if (ref.endsWith(`.${extension}`)) { - return import(pathToFileURL(ref)); // eslint-disable-line node/no-unsupported-features/es-syntax + return import(pathToFileURL(ref)); } } @@ -207,12 +180,12 @@ const run = async options => { // Install dependency tracker after the require configuration has been evaluated // to make sure we also track dependencies with custom require hooks - dependencyTracking.install(testPath); + dependencyTracking.install(require.extensions, testPath); if (options.debug && options.debug.port !== undefined && options.debug.host !== undefined) { // If an inspector was active when the main process started, and is // already active for the worker process, do not open a new one. - const inspector = require('inspector'); // eslint-disable-line node/no-unsupported-features/node-builtins + const {default: inspector} = await import('inspector'); if (!options.debug.active || inspector.url() === undefined) { inspector.open(options.debug.port, options.debug.host, true); } @@ -224,7 +197,7 @@ const run = async options => { await load(testPath); - if (accessedRunner) { + if (flags.loadedMain) { // Unreference the channel if the test file required AVA. This stops it // from keeping the event loop busy, which means the `beforeExit` event can be // used to detect when tests stall. @@ -249,7 +222,6 @@ const onError = error => { }; if (isRunningInThread) { - const {workerData} = require('worker_threads'); const {options} = workerData; delete workerData.options; // Don't allow user code access. run(options).catch(onError); // eslint-disable-line promise/prefer-await-to-then diff --git a/lib/worker/channel.js b/lib/worker/channel.cjs similarity index 97% rename from lib/worker/channel.js rename to lib/worker/channel.cjs index 540706222..cf48608fd 100644 --- a/lib/worker/channel.js +++ b/lib/worker/channel.cjs @@ -4,9 +4,10 @@ const {MessageChannel} = require('worker_threads'); const pEvent = require('p-event'); -const timers = require('../now-and-timers'); -const {get: getOptions} = require('./options'); -const {isRunningInChildProcess, isRunningInThread} = require('./utils'); +const timers = require('../now-and-timers.cjs'); + +const {get: getOptions} = require('./options.cjs'); +const {isRunningInChildProcess, isRunningInThread} = require('./utils.cjs'); const selectAvaMessage = type => message => message.ava && message.ava.type === type; @@ -89,7 +90,7 @@ class IpcHandle { let handle; if (isRunningInChildProcess) { - const {controlFlow} = require('../ipc-flow-control'); + const {controlFlow} = require('../ipc-flow-control.cjs'); handle = new IpcHandle(controlFlow(process)); } else if (isRunningInThread) { const {parentPort} = require('worker_threads'); diff --git a/lib/worker/dependency-tracker.js b/lib/worker/dependency-tracker.js index f1fa7c839..2f35c61c7 100644 --- a/lib/worker/dependency-tracker.js +++ b/lib/worker/dependency-tracker.js @@ -1,6 +1,4 @@ -/* eslint-disable node/no-deprecated-api */ -'use strict'; -const channel = require('./channel'); +import channel from './channel.cjs'; const seenDependencies = new Set(); let newDependencies = []; @@ -14,8 +12,6 @@ function flush() { newDependencies = []; } -exports.flush = flush; - function track(filename) { if (seenDependencies.has(filename)) { return; @@ -29,20 +25,20 @@ function track(filename) { newDependencies.push(filename); } -exports.track = track; - -function install(testPath) { - for (const ext of Object.keys(require.extensions)) { - const wrappedHandler = require.extensions[ext]; - - require.extensions[ext] = (module, filename) => { - if (filename !== testPath) { - track(filename); - } - - wrappedHandler(module, filename); - }; +export default { + flush, + track, + install(extensions, testPath) { + for (const ext of Object.keys(extensions)) { + const wrappedHandler = extensions[ext]; + + extensions[ext] = (module, filename) => { + if (filename !== testPath) { + track(filename); + } + + wrappedHandler(module, filename); + }; + } } -} - -exports.install = install; +}; diff --git a/lib/worker/guard-environment.cjs b/lib/worker/guard-environment.cjs new file mode 100644 index 000000000..ae0418c63 --- /dev/null +++ b/lib/worker/guard-environment.cjs @@ -0,0 +1,19 @@ +'use strict'; +const path = require('path'); + +const {isRunningInThread, isRunningInChildProcess} = require('./utils.cjs'); + +// Check if the test is being run without AVA cli +if (!isRunningInChildProcess && !isRunningInThread) { + const chalk = require('chalk'); // Use default Chalk instance. + if (process.argv[1]) { + const fp = path.relative('.', process.argv[1]); + + console.log(); + console.error(`Test files must be run with the AVA CLI:\n\n ${chalk.grey.dim('$')} ${chalk.cyan('ava ' + fp)}\n`); + + process.exit(1); // eslint-disable-line unicorn/no-process-exit + } else { + throw new Error('The ’ava’ module can only be imported in test files'); + } +} diff --git a/lib/worker/line-numbers.js b/lib/worker/line-numbers.cjs similarity index 83% rename from lib/worker/line-numbers.js rename to lib/worker/line-numbers.cjs index d3cd169c5..150b4d0dc 100644 --- a/lib/worker/line-numbers.js +++ b/lib/worker/line-numbers.cjs @@ -1,3 +1,6 @@ +'use strict'; +// TODO: Convert to ESM + function parse(file) { const fs = require('fs'); const acorn = require('acorn'); @@ -5,7 +8,8 @@ function parse(file) { const ast = acorn.parse(fs.readFileSync(file, 'utf8'), { ecmaVersion: 11, - locations: true + locations: true, + sourceType: 'module' }); const locations = []; @@ -57,6 +61,7 @@ module.exports = ({file, lineNumbers = []}) => { } // Avoid loading these until we actually need to select tests by line number. + const {pathToFileURL} = require('url'); const callsites = require('callsites'); const sourceMapSupport = require('source-map-support'); @@ -66,7 +71,14 @@ module.exports = ({file, lineNumbers = []}) => { return () => { // Assume this is called from a test declaration, which is located in the file. // If not… don't select the test! - const callSite = callsites().find(callSite => callSite.getFileName() === file); + const callSite = callsites().find(callSite => { + const current = callSite.getFileName(); + if (file.startsWith('file://')) { + return current.startsWith('file://') ? file === current : file === pathToFileURL(current).toString(); + } + + return current.startsWith('file://') ? pathToFileURL(file).toString() === current : file === current; + }); if (!callSite) { return false; } diff --git a/lib/worker/main.cjs b/lib/worker/main.cjs new file mode 100644 index 000000000..b6afc0d00 --- /dev/null +++ b/lib/worker/main.cjs @@ -0,0 +1,12 @@ +'use strict'; +require('./guard-environment.cjs'); // eslint-disable-line import/no-unassigned-import + +const assert = require('assert'); + +const {flags, refs} = require('./state.cjs'); + +assert(refs.runnerChain); + +flags.loadedMain = true; + +module.exports = refs.runnerChain; diff --git a/lib/worker/main.js b/lib/worker/main.js deleted file mode 100644 index 9ee9c655c..000000000 --- a/lib/worker/main.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; -const runner = require('./base').getRunner(); -module.exports = runner.chain; diff --git a/lib/worker/options.js b/lib/worker/options.cjs similarity index 100% rename from lib/worker/options.js rename to lib/worker/options.cjs diff --git a/lib/worker/plugin.js b/lib/worker/plugin.cjs similarity index 83% rename from lib/worker/plugin.js rename to lib/worker/plugin.cjs index 3d4e2dfd6..f7935ca66 100644 --- a/lib/worker/plugin.js +++ b/lib/worker/plugin.cjs @@ -1,12 +1,24 @@ const pkg = require('../../package.json'); -const baseWorker = require('./base'); -const options = require('./options'); + +const {registerSharedWorker: register} = require('./channel.cjs'); +const options = require('./options.cjs'); +const {sharedWorkerTeardowns, waitForReady} = require('./state.cjs'); + +require('./guard-environment.cjs'); // eslint-disable-line import/no-unassigned-import const workers = new Map(); const workerTeardownFns = new WeakMap(); function createSharedWorker(filename, initialData, teardown) { - const channel = baseWorker.registerSharedWorker(filename, initialData, teardown); + const {channel, forceUnref, ready} = register(filename, initialData, teardown); + waitForReady.push(ready); + sharedWorkerTeardowns.push(async () => { + try { + await teardown(); + } finally { + forceUnref(); + } + }); class ReceivedMessage { constructor(id, data) { @@ -90,6 +102,8 @@ function registerSharedWorker({ throw new Error(`This version of AVA (${pkg.version}) does not support any of the desired shared worker protocols: ${supportedProtocols.join()}`); } + filename = String(filename); // Allow URL instances. + let worker = workers.get(filename); if (worker === undefined) { worker = createSharedWorker(filename, initialData, async () => { diff --git a/lib/worker/state.cjs b/lib/worker/state.cjs new file mode 100644 index 000000000..9e7deaeaf --- /dev/null +++ b/lib/worker/state.cjs @@ -0,0 +1,5 @@ +'use strict'; +exports.flags = {loadedMain: false}; +exports.refs = {runnerChain: null}; +exports.sharedWorkerTeardowns = []; +exports.waitForReady = []; diff --git a/lib/worker/utils.js b/lib/worker/utils.cjs similarity index 100% rename from lib/worker/utils.js rename to lib/worker/utils.cjs diff --git a/package-lock.json b/package-lock.json index c67af1861..4e8611aba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,7 +79,6 @@ "fs-extra": "^9.1.0", "get-stream": "^6.0.1", "it-first": "^1.0.6", - "proxyquire": "^2.1.3", "replace-string": "^3.1.0", "sinon": "^10.0.0", "source-map-fixtures": "^2.1.0", @@ -5232,19 +5231,6 @@ "node": "^10.12.0 || >=12.0.0" } }, - "node_modules/fill-keys": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz", - "integrity": "sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA=", - "dev": true, - "dependencies": { - "is-object": "~1.0.1", - "merge-descriptors": "~1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -6464,15 +6450,6 @@ "obj-props": "^1.0.0" } }, - "node_modules/is-object": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.2.tgz", - "integrity": "sha512-2rRIahhZr2UWb45fIOuvZGpFtz0TyOZLf32KxBbSoUCeZR495zCKlWUKKUByk3geS2eAs7ZAABt0Y/Rx0GiQGA==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-path-cwd": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz", @@ -7392,12 +7369,6 @@ "node": ">=6" } }, - "node_modules/merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", - "dev": true - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -7583,12 +7554,6 @@ "node": ">=10" } }, - "node_modules/module-not-found-error": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz", - "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", - "dev": true - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -8856,17 +8821,6 @@ "node": ">=4" } }, - "node_modules/proxyquire": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-2.1.3.tgz", - "integrity": "sha512-BQWfCqYM+QINd+yawJz23tbBM40VIGXOdDw3X344KcclI/gtBbdWF6SlQ4nK/bYhF9d27KYug9WzljHC6B9Ysg==", - "dev": true, - "dependencies": { - "fill-keys": "^1.0.2", - "module-not-found-error": "^1.0.1", - "resolve": "^1.11.1" - } - }, "node_modules/psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -18373,16 +18327,6 @@ "flat-cache": "^3.0.4" } }, - "fill-keys": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz", - "integrity": "sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA=", - "dev": true, - "requires": { - "is-object": "~1.0.1", - "merge-descriptors": "~1.0.0" - } - }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -19251,12 +19195,6 @@ "obj-props": "^1.0.0" } }, - "is-object": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.2.tgz", - "integrity": "sha512-2rRIahhZr2UWb45fIOuvZGpFtz0TyOZLf32KxBbSoUCeZR495zCKlWUKKUByk3geS2eAs7ZAABt0Y/Rx0GiQGA==", - "dev": true - }, "is-path-cwd": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz", @@ -19967,12 +19905,6 @@ } } }, - "merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", - "dev": true - }, "merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -20117,12 +20049,6 @@ "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", "dev": true }, - "module-not-found-error": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz", - "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", - "dev": true - }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -21106,17 +21032,6 @@ "integrity": "sha512-2yma2tog9VaRZY2mn3Wq51uiSW4NcPYT1cQdBagwyrznrilKSZwIZ0UG3ZPL/mx+axEns0hE35T5ufOYZXEnBQ==", "dev": true }, - "proxyquire": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-2.1.3.tgz", - "integrity": "sha512-BQWfCqYM+QINd+yawJz23tbBM40VIGXOdDw3X344KcclI/gtBbdWF6SlQ4nK/bYhF9d27KYug9WzljHC6B9Ysg==", - "dev": true, - "requires": { - "fill-keys": "^1.0.2", - "module-not-found-error": "^1.0.1", - "resolve": "^1.11.1" - } - }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", diff --git a/package.json b/package.json index 2646980de..875573d26 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "require": "./entrypoints/plugin.cjs" } }, + "type": "module", "engines": { "node": ">=12.22 <13 || >=14.15 <15 || >=16" }, @@ -136,7 +137,6 @@ "fs-extra": "^9.1.0", "get-stream": "^6.0.1", "it-first": "^1.0.6", - "proxyquire": "^2.1.3", "replace-string": "^3.1.0", "sinon": "^10.0.0", "source-map-fixtures": "^2.1.0", diff --git a/plugin.d.ts b/plugin.d.ts index 522bf35c8..faff6b115 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -1,3 +1,5 @@ +import {URL} from 'url'; + export namespace SharedWorker { export type ProtocolIdentifier = 'experimental'; @@ -46,7 +48,7 @@ export namespace SharedWorker { export namespace Plugin { export type RegistrationOptions = { - readonly filename: string; + readonly filename: string | URL; readonly initialData?: Data; readonly supportedProtocols: readonly Identifier[]; readonly teardown?: () => void; diff --git a/test-d/assertions-as-type-guards.ts b/test-d/assertions-as-type-guards.ts index b9343e70b..364189b95 100644 --- a/test-d/assertions-as-type-guards.ts +++ b/test-d/assertions-as-type-guards.ts @@ -1,5 +1,6 @@ import {expectType} from 'tsd'; -import test from '..'; // eslint-disable-line import/no-unresolved + +import test from '..'; type Expected = {foo: 'bar'}; const expected: Expected = {foo: 'bar'}; diff --git a/test-d/context.ts b/test-d/context.ts index 3cfc2d251..144d93940 100644 --- a/test-d/context.ts +++ b/test-d/context.ts @@ -1,5 +1,6 @@ import {expectError, expectType} from 'tsd'; -import anyTest, {Macro, TestInterface} from '..'; // eslint-disable-line import/no-unresolved + +import anyTest, {Macro, TestInterface} from '..'; interface Context { foo: string; diff --git a/test-d/like.ts b/test-d/like.ts index d714d7387..5dd772c4d 100644 --- a/test-d/like.ts +++ b/test-d/like.ts @@ -1,4 +1,4 @@ -import test from '..'; // eslint-disable-line import/no-unresolved +import test from '..'; test('like', t => { t.like({ diff --git a/test-d/macros.ts b/test-d/macros.ts index 81c916ce7..533a42717 100644 --- a/test-d/macros.ts +++ b/test-d/macros.ts @@ -1,5 +1,6 @@ import {expectType} from 'tsd'; -import test, {ExecutionContext, Macro} from '..'; // eslint-disable-line import/no-unresolved + +import test, {ExecutionContext, Macro} from '..'; // Explicitly type as a macro. { diff --git a/test-d/plugin.ts b/test-d/plugin.ts index 7b90e066e..8c84ed296 100644 --- a/test-d/plugin.ts +++ b/test-d/plugin.ts @@ -1,5 +1,6 @@ import {expectType} from 'tsd'; -import * as plugin from '../plugin'; // eslint-disable-line import/no-unresolved + +import * as plugin from '../plugin'; expectType(plugin.registerSharedWorker({filename: '', supportedProtocols: ['experimental']})); diff --git a/test-d/snapshot.ts b/test-d/snapshot.ts index 4a6c416e5..61cd4a1c5 100644 --- a/test-d/snapshot.ts +++ b/test-d/snapshot.ts @@ -1,5 +1,6 @@ import {expectError} from 'tsd'; -import test from '..'; // eslint-disable-line import/no-unresolved + +import test from '..'; test('snapshot', t => { t.snapshot({foo: 'bar'}); diff --git a/test-d/throws.ts b/test-d/throws.ts index 205ba6c0c..fa9dcd78f 100644 --- a/test-d/throws.ts +++ b/test-d/throws.ts @@ -1,5 +1,6 @@ import {expectType} from 'tsd'; -import test from '..'; // eslint-disable-line import/no-unresolved + +import test from '..'; class CustomError extends Error { foo: string; diff --git a/test-d/try-commit.ts b/test-d/try-commit.ts index 29ee17b03..055c3e931 100644 --- a/test-d/try-commit.ts +++ b/test-d/try-commit.ts @@ -1,5 +1,6 @@ import {expectType} from 'tsd'; -import test, {ExecutionContext, Macro} from '..'; // eslint-disable-line import/no-unresolved + +import test, {ExecutionContext, Macro} from '..'; test('attempt', async t => { const attempt = await t.try( diff --git a/test-tap/api.js b/test-tap/api.js index a2b9ab108..2d4137faa 100644 --- a/test-tap/api.js +++ b/test-tap/api.js @@ -1,28 +1,29 @@ -'use strict'; -require('../lib/chalk').set(); +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; -const path = require('path'); -const fs = require('fs'); -const del = require('del'); -const {test} = require('tap'); -const Api = require('../lib/api'); -const {normalizeGlobs} = require('../lib/globs'); -const providerManager = require('../lib/provider-manager'); +import del from 'del'; +import {test} from 'tap'; +import Api from '../lib/api.js'; +import {normalizeGlobs} from '../lib/globs.js'; +import providerManager from '../lib/provider-manager.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); const ROOT_DIR = path.join(__dirname, '..'); -function apiCreator(options = {}) { +async function apiCreator(options = {}) { options.projectDir = options.projectDir || ROOT_DIR; if (options.babelConfig !== undefined) { options.providers = [{ type: 'babel', - main: providerManager.babel(options.projectDir).main({config: options.babelConfig}) + main: (await providerManager.babel(options.projectDir)).main({config: options.babelConfig}) }]; } options.chalkOptions = {level: 0}; options.concurrency = 2; - options.extensions = options.extensions || ['js']; + options.extensions = options.extensions || ['cjs']; options.experiments = {}; options.globs = normalizeGlobs({files: options.files, ignoredByWatcher: options.ignoredByWatcher, extensions: options.extensions, providers: []}); const instance = new Api(options); @@ -36,19 +37,19 @@ const opts = [ ]; for (const opt of opts) { - test(`test.meta - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator({ + test(`test.meta - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator({ ...opt, snapshotDir: 'snapshot-fixture' }); - return api.run({files: [path.join(__dirname, 'fixture', 'meta.js')]}) + return api.run({files: [path.join(__dirname, 'fixture', 'meta.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 2); }); }); - test(`fail-fast mode - workerThreads: ${opt.workerThreads} - single file & serial`, t => { - const api = apiCreator({ + test(`fail-fast mode - workerThreads: ${opt.workerThreads} - single file & serial`, async t => { + const api = await apiCreator({ ...opt, failFast: true }); @@ -71,7 +72,7 @@ for (const opt of opts) { }); }); - return api.run({files: [path.join(__dirname, 'fixture/fail-fast/single-file/test.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/fail-fast/single-file/test.cjs')]}) .then(runStatus => { t.ok(api.options.failFast); t.strictSame(tests, [{ @@ -88,8 +89,8 @@ for (const opt of opts) { t.equal(runStatus.stats.failedTests, 1); }); }); - test(`fail-fast mode - workerThreads: ${opt.workerThreads} - multiple files & serial`, t => { - const api = apiCreator({ + test(`fail-fast mode - workerThreads: ${opt.workerThreads} - multiple files & serial`, async t => { + const api = await apiCreator({ ...opt, failFast: true, serial: true @@ -116,18 +117,18 @@ for (const opt of opts) { }); return api.run({files: [ - path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), - path.join(__dirname, 'fixture/fail-fast/multiple-files/passes.js') + path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), + path.join(__dirname, 'fixture/fail-fast/multiple-files/passes.cjs') ]}) .then(runStatus => { t.ok(api.options.failFast); t.strictSame(tests, [{ ok: true, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), title: 'first pass' }, { ok: false, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), title: 'second fail' }]); t.equal(runStatus.stats.passedTests, 1); @@ -135,7 +136,7 @@ for (const opt of opts) { }); }); test(`fail-fast mode - workerThreads: ${opt.workerThreads} - multiple files & interrupt`, async t => { - const api = apiCreator({ + const api = await apiCreator({ ...opt, failFast: true, concurrency: 2 @@ -161,8 +162,8 @@ for (const opt of opts) { }); }); - const fails = path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'); - const passesSlow = path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'); + const fails = path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'); + const passesSlow = path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.cjs'); const runStatus = await api.run({files: [fails, passesSlow]}); t.ok(api.options.failFast); @@ -172,27 +173,27 @@ for (const opt of opts) { t.strictSame(tests.filter(({testFile}) => testFile === fails), [{ ok: true, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), title: 'first pass' }, { ok: false, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), title: 'second fail' }, { ok: true, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.cjs'), title: 'third pass' }]); if (runStatus.stats.passedTests === 3) { t.strictSame(tests.filter(({testFile}) => testFile === passesSlow), [{ ok: true, - testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'), + testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.cjs'), title: 'first pass' }]); } }); - test(`fail-fast mode - workerThreads: ${opt.workerThreads} - crash & serial`, t => { - const api = apiCreator({ + test(`fail-fast mode - workerThreads: ${opt.workerThreads} - crash & serial`, async t => { + const api = await apiCreator({ ...opt, failFast: true, serial: true @@ -233,21 +234,21 @@ for (const opt of opts) { }); return api.run({files: [ - path.join(__dirname, 'fixture/fail-fast/crash/crashes.js'), - path.join(__dirname, 'fixture/fail-fast/crash/passes.js') + path.join(__dirname, 'fixture/fail-fast/crash/crashes.cjs'), + path.join(__dirname, 'fixture/fail-fast/crash/passes.cjs') ]}) .then(runStatus => { t.ok(api.options.failFast); t.strictSame(tests, []); t.equal(workerFailures.length, 1); - t.equal(workerFailures[0].testFile, path.join(__dirname, 'fixture', 'fail-fast', 'crash', 'crashes.js')); + t.equal(workerFailures[0].testFile, path.join(__dirname, 'fixture', 'fail-fast', 'crash', 'crashes.cjs')); t.equal(runStatus.stats.passedTests, 0); t.equal(runStatus.stats.failedTests, 0); }); }); - test(`fail-fast mode - workerThreads: ${opt.workerThreads} - timeout & serial`, t => { - const api = apiCreator({ + test(`fail-fast mode - workerThreads: ${opt.workerThreads} - timeout & serial`, async t => { + const api = await apiCreator({ ...opt, failFast: true, serial: true, @@ -289,8 +290,8 @@ for (const opt of opts) { }); return api.run({files: [ - path.join(__dirname, 'fixture/fail-fast/timeout/fails.js'), - path.join(__dirname, 'fixture/fail-fast/timeout/passes.js') + path.join(__dirname, 'fixture/fail-fast/timeout/fails.cjs'), + path.join(__dirname, 'fixture/fail-fast/timeout/passes.cjs') ]}) .then(runStatus => { t.ok(api.options.failFast); @@ -301,15 +302,15 @@ for (const opt of opts) { t.equal(runStatus.stats.failedTests, 0); }); }); - test(`fail-fast mode - workerThreads: ${opt.workerThreads} - no errors`, t => { - const api = apiCreator({ + test(`fail-fast mode - workerThreads: ${opt.workerThreads} - no errors`, async t => { + const api = await apiCreator({ ...opt, failFast: true }); return api.run({files: [ - path.join(__dirname, 'fixture/fail-fast/without-error/a.js'), - path.join(__dirname, 'fixture/fail-fast/without-error/b.js') + path.join(__dirname, 'fixture/fail-fast/without-error/a.cjs'), + path.join(__dirname, 'fixture/fail-fast/without-error/b.cjs') ]}) .then(runStatus => { t.ok(api.options.failFast); @@ -317,32 +318,32 @@ for (const opt of opts) { t.equal(runStatus.stats.failedTests, 0); }); }); - test(`serial execution mode - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator({ + test(`serial execution mode - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator({ ...opt, serial: true }); - return api.run({files: [path.join(__dirname, 'fixture/serial.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/serial.cjs')]}) .then(runStatus => { t.ok(api.options.serial); t.equal(runStatus.stats.passedTests, 3); t.equal(runStatus.stats.failedTests, 0); }); }); - test(`run from package.json folder by default - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator(opt); + test(`run from package.json folder by default - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator(opt); - return api.run({files: [path.join(__dirname, 'fixture/process-cwd-default.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/process-cwd-default.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`stack traces for exceptions are corrected using a source map file - workerThreads: ${opt.workerThreads}`, t => { + test(`stack traces for exceptions are corrected using a source map file - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator({ + const api = await apiCreator({ ...opt, cacheEnabled: true }); @@ -352,21 +353,21 @@ for (const opt of opts) { if (evt.type === 'uncaught-exception') { t.match(evt.err.message, /Thrown by source-map-fixtures/); t.match(evt.err.stack, /^.*?\brun\b.*source-map-fixtures.src.throws.js:1.*$/m); - t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file.js:4.*$/m); + t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file.cjs:5.*$/m); } }); }); - return api.run({files: [path.join(__dirname, 'fixture/source-map-file.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/source-map-file.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`stack traces for exceptions are corrected using a source map file in what looks like a browser env - workerThreads: ${opt.workerThreads}`, t => { + test(`stack traces for exceptions are corrected using a source map file in what looks like a browser env - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator({ + const api = await apiCreator({ ...opt, cacheEnabled: true }); @@ -376,18 +377,18 @@ for (const opt of opts) { if (evt.type === 'uncaught-exception') { t.match(evt.err.message, /Thrown by source-map-fixtures/); t.match(evt.err.stack, /^.*?\brun\b.*source-map-fixtures.src.throws.js:1.*$/m); - t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file-browser-env.js:7.*$/m); + t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file-browser-env.cjs:8.*$/m); } }); }); - return api.run({files: [path.join(__dirname, 'fixture/source-map-file-browser-env.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/source-map-file-browser-env.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`enhanced assertion formatting necessary whitespace and empty strings - workerThreads: ${opt.workerThreads}`, t => { + test(`enhanced assertion formatting necessary whitespace and empty strings - workerThreads: ${opt.workerThreads}`, async t => { const expected = [ [ /foo === "" && "" === foo/, @@ -411,9 +412,9 @@ for (const opt of opts) { ]; t.plan(15); - const api = apiCreator({ + const api = await apiCreator({ ...opt, - files: ['test-tap/fixture/enhanced-assertion-formatting.js'], + files: ['test-tap/fixture/enhanced-assertion-formatting.cjs'], babelConfig: true }); const errors = []; @@ -424,7 +425,7 @@ for (const opt of opts) { } }); }); - return api.run({files: [path.join(__dirname, 'fixture/enhanced-assertion-formatting.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/enhanced-assertion-formatting.cjs')]}) .then(runStatus => { t.equal(errors.length, 3); t.equal(runStatus.stats.passedTests, 0); @@ -437,10 +438,10 @@ for (const opt of opts) { }); }); - test(`stack traces for exceptions are corrected using a source map file (cache off) - workerThreads: ${opt.workerThreads}`, t => { + test(`stack traces for exceptions are corrected using a source map file (cache off) - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator({ + const api = await apiCreator({ ...opt, cacheEnabled: false }); @@ -450,21 +451,21 @@ for (const opt of opts) { if (evt.type === 'uncaught-exception') { t.match(evt.err.message, /Thrown by source-map-fixtures/); t.match(evt.err.stack, /^.*?\brun\b.*source-map-fixtures.src.throws.js:1.*$/m); - t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file.js:4.*$/m); + t.match(evt.err.stack, /^.*?Immediate\b.*source-map-file.cjs:5.*$/m); } }); }); - return api.run({files: [path.join(__dirname, 'fixture/source-map-file.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/source-map-file.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`stack traces for exceptions are corrected using a source map, taking an initial source map for the test file into account (cache on) - workerThreads: ${opt.workerThreads}`, t => { + test(`stack traces for exceptions are corrected using a source map, taking an initial source map for the test file into account (cache on) - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator({ + const api = await apiCreator({ ...opt, cacheEnabled: true }); @@ -474,21 +475,21 @@ for (const opt of opts) { if (evt.type === 'uncaught-exception') { t.match(evt.err.message, /Thrown by source-map-fixtures/); t.match(evt.err.stack, /^.*?\brun\b.*source-map-fixtures.src.throws.js:1.*$/m); - t.match(evt.err.stack, /^.*?Immediate\b.*source-map-initial-input.js:14.*$/m); + t.match(evt.err.stack, /^.*?Immediate\b.*source-map-initial.cjs:23.*$/m); } }); }); - return api.run({files: [path.join(__dirname, 'fixture/source-map-initial.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/source-map-initial.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`stack traces for exceptions are corrected using a source map, taking an initial source map for the test file into account (cache off) - workerThreads: ${opt.workerThreads}`, t => { + test(`stack traces for exceptions are corrected using a source map, taking an initial source map for the test file into account (cache off) - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator({ + const api = await apiCreator({ ...opt, cacheEnabled: false }); @@ -498,28 +499,28 @@ for (const opt of opts) { if (evt.type === 'uncaught-exception') { t.match(evt.err.message, /Thrown by source-map-fixtures/); t.match(evt.err.stack, /^.*?\brun\b.*source-map-fixtures.src.throws.js:1.*$/m); - t.match(evt.err.stack, /^.*?Immediate\b.*source-map-initial-input.js:14.*$/m); + t.match(evt.err.stack, /^.*?Immediate\b.*source-map-initial.cjs:23.*$/m); } }); }); - return api.run({files: [path.join(__dirname, 'fixture/source-map-initial.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/source-map-initial.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`absolute paths - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator(opt); + test(`absolute paths - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator(opt); - return api.run({files: [path.resolve('test-tap/fixture/es2015.js')]}) + return api.run({files: [path.resolve('test-tap/fixture/es2015.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`symlink to directory containing test files - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator({...opt, files: ['test-tap/fixture/symlink/*.js']}); + test(`symlink to directory containing test files - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator({...opt, files: ['test-tap/fixture/symlink/*.cjs']}); return api.run() .then(runStatus => { @@ -527,60 +528,57 @@ for (const opt of opts) { }); }); - test(`symlink to test file directly - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator(opt); + test(`symlink to test file directly - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator(opt); - return api.run({files: [path.join(__dirname, 'fixture/symlinkfile.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/symlinkfile.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); - test(`test file in node_modules is ignored - workerThreads: ${opt.workerThreads}`, t => { + test(`test file in node_modules is ignored - workerThreads: ${opt.workerThreads}`, async t => { t.plan(1); - const api = apiCreator(opt); - return api.run({files: [path.join(__dirname, 'fixture/ignored-dirs/node_modules/test.js')]}) + const api = await apiCreator(opt); + return api.run({files: [path.join(__dirname, 'fixture/ignored-dirs/node_modules/test.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.declaredTests, 0); }); }); - test(`Node.js-style --require CLI argument - workerThreads: ${opt.workerThreads}`, t => { - const requirePath = './' + path.relative('.', path.join(__dirname, 'fixture/install-global.js')).replace(/\\/g, '/'); + test(`Node.js-style --require CLI argument - workerThreads: ${opt.workerThreads}`, async t => { + const requirePath = './' + path.relative('.', path.join(__dirname, 'fixture/install-global.cjs')).replace(/\\/g, '/'); - const api = apiCreator({ + const api = await apiCreator({ ...opt, require: [requirePath] }); - return api.run({files: [path.join(__dirname, 'fixture/validate-installed-global.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/validate-installed-global.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); test(`Node.js-style --require CLI argument module not found - workerThreads: ${opt.workerThreads}`, t => { - t.throws(() => { - /* eslint no-new: 0 */ - apiCreator({...opt, require: ['foo-bar']}); - }, /^Could not resolve required module ’foo-bar’$/); + t.rejects(apiCreator({...opt, require: ['foo-bar']}), /^Could not resolve required module ’foo-bar’$/); t.end(); }); - test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, t => { + test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, async t => { del.sync(path.join(__dirname, 'fixture/caching/node_modules')); - const api = apiCreator({ + const api = await apiCreator({ ...opt, babelConfig: true, projectDir: path.join(__dirname, 'fixture/caching') }); - return api.run({files: [path.join(__dirname, 'fixture/caching/test.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/caching/test.cjs')]}) .then(() => { const files = fs.readdirSync(path.join(__dirname, 'fixture/caching/node_modules/.cache/ava')); - t.equal(files.filter(x => x.endsWith('.js')).length, 1); + t.equal(files.filter(x => x.endsWith('.cjs')).length, 1); t.equal(files.filter(x => x.endsWith('.map')).length, 1); if (files.length === 3) { // This file may be written locally, but not in CI. @@ -591,25 +589,25 @@ for (const opt of opts) { }); }); - test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, t => { + test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => { del.sync(path.join(__dirname, 'fixture/caching/node_modules')); - const api = apiCreator({ + const api = await apiCreator({ ...opt, projectDir: path.join(__dirname, 'fixture/caching'), cacheEnabled: false }); - return api.run({files: [path.join(__dirname, 'fixture/caching/test.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/caching/test.cjs')]}) .then(() => { t.notOk(fs.existsSync(path.join(__dirname, 'fixture/caching/node_modules/.cache/ava'))); }); }); - test(`test file with only skipped tests does not create a failure - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator(); + test(`test file with only skipped tests does not create a failure - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator(); - return api.run({...opt, files: [path.join(__dirname, 'fixture/skip-only.js')]}) + return api.run({...opt, files: [path.join(__dirname, 'fixture/skip-only.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.selectedTests, 1); t.equal(runStatus.stats.skippedTests, 1); @@ -617,10 +615,10 @@ for (const opt of opts) { }); }); - test(`test file with only skipped tests does not run hooks - workerThreads: ${opt.workerThreads}`, t => { - const api = apiCreator(opt); + test(`test file with only skipped tests does not run hooks - workerThreads: ${opt.workerThreads}`, async t => { + const api = await apiCreator(opt); - return api.run({files: [path.join(__dirname, 'fixture/hooks-skipped.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/hooks-skipped.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.selectedTests, 1); t.equal(runStatus.stats.skippedTests, 1); @@ -630,20 +628,20 @@ for (const opt of opts) { }); }); - test(`emits dependencies for test files - workerThreads: ${opt.workerThreads}`, t => { + test(`emits dependencies for test files - workerThreads: ${opt.workerThreads}`, async t => { t.plan(8); - const api = apiCreator({ + const api = await apiCreator({ ...opt, - files: ['test-tap/fixture/with-dependencies/*test*.js'], - require: [path.resolve('test-tap/fixture/with-dependencies/require-custom.js')] + files: ['test-tap/fixture/with-dependencies/*test*.cjs'], + require: [path.resolve('test-tap/fixture/with-dependencies/require-custom.cjs')] }); const testFiles = new Set([ - path.resolve('test-tap/fixture/with-dependencies/no-tests.js'), - path.resolve('test-tap/fixture/with-dependencies/test.js'), - path.resolve('test-tap/fixture/with-dependencies/test-failure.js'), - path.resolve('test-tap/fixture/with-dependencies/test-uncaught-exception.js') + path.resolve('test-tap/fixture/with-dependencies/no-tests.cjs'), + path.resolve('test-tap/fixture/with-dependencies/test.cjs'), + path.resolve('test-tap/fixture/with-dependencies/test-failure.cjs'), + path.resolve('test-tap/fixture/with-dependencies/test-uncaught-exception.cjs') ]); const sourceFiles = [ @@ -664,15 +662,15 @@ for (const opt of opts) { return api.run(); }); - test(`verify test count - workerThreads: ${opt.workerThreads}`, t => { + test(`verify test count - workerThreads: ${opt.workerThreads}`, async t => { t.plan(4); - const api = apiCreator(opt); + const api = await apiCreator(opt); return api.run({files: [ - path.join(__dirname, 'fixture/test-count.js'), - path.join(__dirname, 'fixture/test-count-2.js'), - path.join(__dirname, 'fixture/test-count-3.js') + path.join(__dirname, 'fixture/test-count.cjs'), + path.join(__dirname, 'fixture/test-count-2.cjs'), + path.join(__dirname, 'fixture/test-count-3.cjs') ]}).then(runStatus => { t.equal(runStatus.stats.passedTests, 4, 'pass count'); t.equal(runStatus.stats.failedTests, 3, 'fail count'); @@ -681,10 +679,10 @@ for (const opt of opts) { }); }); - test(`using --match with matching tests will only report those passing tests - workerThreads: ${opt.workerThreads}`, t => { + test(`using --match with matching tests will only report those passing tests - workerThreads: ${opt.workerThreads}`, async t => { t.plan(3); - const api = apiCreator({ + const api = await apiCreator({ ...opt, match: ['this test will match'] }); @@ -699,21 +697,21 @@ for (const opt of opts) { }); return api.run({files: [ - path.join(__dirname, 'fixture/match-no-match.js'), - path.join(__dirname, 'fixture/match-no-match-2.js'), - path.join(__dirname, 'fixture/test-count.js') + path.join(__dirname, 'fixture/match-no-match.cjs'), + path.join(__dirname, 'fixture/match-no-match-2.cjs'), + path.join(__dirname, 'fixture/test-count.cjs') ]}).then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); }); } -test('run from package.json folder by default', t => { - const api = apiCreator({ +test('run from package.json folder by default', async t => { + const api = await apiCreator({ workerThreads: false }); - return api.run({files: [path.join(__dirname, 'fixture/process-cwd-default.js')]}) + return api.run({files: [path.join(__dirname, 'fixture/process-cwd-default.cjs')]}) .then(runStatus => { t.equal(runStatus.stats.passedTests, 1); }); diff --git a/test-tap/assert.js b/test-tap/assert.js index 40d6e3093..491cd459f 100644 --- a/test-tap/assert.js +++ b/test-tap/assert.js @@ -1,12 +1,14 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({chalkOptions: {level: 0}}); +import path from 'path'; +import {fileURLToPath} from 'url'; -const path = require('path'); -const stripAnsi = require('strip-ansi'); -const {test} = require('tap'); -const assert = require('../lib/assert'); -const snapshotManager = require('../lib/snapshot-manager'); +import stripAnsi from 'strip-ansi'; +import {test} from 'tap'; + +import * as assert from '../lib/assert.js'; +import * as snapshotManager from '../lib/snapshot-manager.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +setOptions({chalkOptions: {level: 0}}); let lastFailure = null; let lastPassed = false; @@ -1620,9 +1622,9 @@ test('.snapshot()', t => { // Ignore errors and make sure not to run tests with the `-b` (bail) option. const updating = false; - const projectDir = path.join(__dirname, 'fixture'); + const projectDir = fileURLToPath(new URL('fixture', import.meta.url)); const manager = snapshotManager.load({ - file: path.join(projectDir, 'assert.js'), + file: path.join(projectDir, 'assert.cjs'), projectDir, fixedLocation: null, recordNewSnapshots: updating, diff --git a/test-tap/chalk.js b/test-tap/chalk.js index d4965ea4f..98dace000 100644 --- a/test-tap/chalk.js +++ b/test-tap/chalk.js @@ -1,14 +1,9 @@ -'use strict'; -const {test} = require('tap'); -const chalk = require('../lib/chalk'); +import {test} from 'tap'; -test('throws an error when trying to access chalk config and chalk config is not configured', t => { - t.throws(chalk.get, 'Chalk has not yet been configured'); - t.end(); -}); +import {set} from '../lib/chalk.js'; test('throws an error when trying to set chalk config and chalk config is configured', t => { - chalk.set({}); - t.throws(chalk.set, 'Chalk has already been configured'); + set({}); + t.throws(set, 'Chalk has already been configured'); t.end(); }); diff --git a/test-tap/code-excerpt.js b/test-tap/code-excerpt.js index bed81c732..74c8c8e61 100644 --- a/test-tap/code-excerpt.js +++ b/test-tap/code-excerpt.js @@ -1,20 +1,23 @@ -'use strict'; -require('../lib/chalk').set({level: 1}); +import fs from 'fs'; +import {pathToFileURL} from 'url'; -const fs = require('fs'); -const tempWrite = require('temp-write'); -const {Instance: ChalkInstance} = require('chalk'); // eslint-disable-line unicorn/import-style -const {test} = require('tap'); -const codeExcerpt = require('../lib/code-excerpt'); +import _chalk from 'chalk'; +import {test} from 'tap'; +import tempWrite from 'temp-write'; -const chalk = new ChalkInstance({level: 1}); +import {set as setChalk} from '../lib/chalk.js'; +import codeExcerpt from '../lib/code-excerpt.js'; + +setChalk({level: 1}); + +const chalk = new _chalk.Instance({level: 1}); test('read code excerpt', t => { - const file = tempWrite.sync([ + const file = pathToFileURL(tempWrite.sync([ 'function a() {', '\talert();', '}' - ].join('\n')); + ].join('\n'))); const excerpt = codeExcerpt({file, line: 2, isWithinProject: true, isDependency: false}); const expected = [ @@ -28,11 +31,11 @@ test('read code excerpt', t => { }); test('truncate lines', t => { - const file = tempWrite.sync([ + const file = pathToFileURL(tempWrite.sync([ 'function a() {', '\talert();', '}' - ].join('\n')); + ].join('\n'))); const excerpt = codeExcerpt({file, line: 2, isWithinProject: true, isDependency: false}, {maxWidth: 14}); const expected = [ @@ -46,7 +49,7 @@ test('truncate lines', t => { }); test('format line numbers', t => { - const file = tempWrite.sync([ + const file = pathToFileURL(tempWrite.sync([ '', '', '', @@ -58,7 +61,7 @@ test('format line numbers', t => { 'function a() {', '\talert();', '}' - ].join('\n')); + ].join('\n'))); const excerpt = codeExcerpt({file, line: 10, isWithinProject: true, isDependency: false}); const expected = [ @@ -72,7 +75,7 @@ test('format line numbers', t => { }); test('noop if file cannot be read', t => { - const file = tempWrite.sync(''); + const file = pathToFileURL(tempWrite.sync('')); fs.unlinkSync(file); const excerpt = codeExcerpt({file, line: 10, isWithinProject: true, isDependency: false}); @@ -81,13 +84,13 @@ test('noop if file cannot be read', t => { }); test('noop if file is not within project', t => { - const excerpt = codeExcerpt({isWithinProject: false, file: __filename, line: 1}); + const excerpt = codeExcerpt({isWithinProject: false, file: import.meta.url, line: 1}); t.equal(excerpt, null); t.end(); }); test('noop if file is a dependency', t => { - const excerpt = codeExcerpt({isWithinProject: true, isDependency: true, file: __filename, line: 1}); + const excerpt = codeExcerpt({isWithinProject: true, isDependency: true, file: import.meta.url, line: 1}); t.equal(excerpt, null); t.end(); }); diff --git a/test-tap/eslint-plugin-helper.js b/test-tap/eslint-plugin-helper.js index 2b965d22e..343405b73 100644 --- a/test-tap/eslint-plugin-helper.js +++ b/test-tap/eslint-plugin-helper.js @@ -1,11 +1,12 @@ -'use strict'; -const path = require('path'); -const {test} = require('tap'); +import path from 'path'; +import {fileURLToPath} from 'url'; -const {load} = require('../entrypoints/eslint-plugin-helper.cjs'); +import {test} from 'tap'; -const projectDir = path.join(__dirname, 'fixture/eslint-plugin-helper'); -const overrideDir = path.join(__dirname, 'fixture/eslint-plugin-helper/for-overriding'); +import {load} from '../entrypoints/eslint-plugin-helper.cjs'; + +const projectDir = fileURLToPath(new URL('fixture/eslint-plugin-helper', import.meta.url)); +const overrideDir = fileURLToPath(new URL('fixture/eslint-plugin-helper/for-overriding', import.meta.url)); test('caches loaded configuration', t => { const expected = load(projectDir); @@ -40,7 +41,7 @@ test('classifies files according to the configuration', t => { isHelper: false, isTest: false }); - t.same(helper.classifyFile(path.join(projectDir, 'tests/test.js')), { + t.same(helper.classifyFile(path.join(projectDir, 'tests/test.cjs')), { isHelper: false, isTest: false }); @@ -73,7 +74,7 @@ test('classifies files according to configuration override', t => { isHelper: false, isTest: false }); - t.same(helper.classifyFile(path.join(overrideDir, 'tests/test.js')), { + t.same(helper.classifyFile(path.join(overrideDir, 'tests/test.cjs')), { isHelper: false, isTest: false }); diff --git a/test-tap/fixture/_generate-source-map-initial.js b/test-tap/fixture/_generate-source-map-initial.cjs similarity index 75% rename from test-tap/fixture/_generate-source-map-initial.js rename to test-tap/fixture/_generate-source-map-initial.cjs index d425dadc1..ba5d561d3 100644 --- a/test-tap/fixture/_generate-source-map-initial.js +++ b/test-tap/fixture/_generate-source-map-initial.cjs @@ -1,6 +1,7 @@ 'use strict'; const fs = require('fs'); const path = require('path'); + const babel = require('@babel/core'); const transformed = babel.transform(` @@ -19,18 +20,18 @@ test('throw an uncaught exception', t => { }) const run = () => fixture.run(); `.trim(), { - filename: 'source-map-initial-input.js', + filename: 'source-map-initial-input.cjs', sourceMaps: true, presets: ['@ava/stage-4'] }); fs.writeFileSync( - path.join(__dirname, 'source-map-initial.js'), - transformed.code + '\n//# sourceMappingURL=./source-map-initial.js.map\n// Generated using node test/fixtures/_generate-source-map-initial.js\n' + path.join(__dirname, 'source-map-initial.cjs'), + transformed.code + '\n//# sourceMappingURL=./source-map-initial.cjs.map\n// Generated using node test/fixtures/_generate-source-map-initial.js\n' ); fs.writeFileSync( - path.join(__dirname, 'source-map-initial.js.map'), + path.join(__dirname, 'source-map-initial.cjs.map'), JSON.stringify(transformed.map) ); -console.log('Generated source-map-initial.js'); +console.log('Generated source-map-initial.cjs'); diff --git a/test-tap/fixture/assert.js.md b/test-tap/fixture/assert.cjs.md similarity index 69% rename from test-tap/fixture/assert.js.md rename to test-tap/fixture/assert.cjs.md index 6fac103bf..eacab4935 100644 --- a/test-tap/fixture/assert.js.md +++ b/test-tap/fixture/assert.cjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `assert.js` +# Snapshot report for `assert.cjs` -The actual snapshot is saved in `assert.js.snap`. +The actual snapshot is saved in `assert.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/test-tap/fixture/assert.js.snap b/test-tap/fixture/assert.cjs.snap similarity index 100% rename from test-tap/fixture/assert.js.snap rename to test-tap/fixture/assert.cjs.snap diff --git a/test-tap/fixture/ava-paths/target/test.js b/test-tap/fixture/ava-paths/target/test.cjs similarity index 100% rename from test-tap/fixture/ava-paths/target/test.js rename to test-tap/fixture/ava-paths/target/test.cjs diff --git a/test-tap/fixture/caching/test.js b/test-tap/fixture/caching/test.cjs similarity index 100% rename from test-tap/fixture/caching/test.js rename to test-tap/fixture/caching/test.cjs diff --git a/test-tap/fixture/enhanced-assertion-formatting.js b/test-tap/fixture/enhanced-assertion-formatting.cjs similarity index 100% rename from test-tap/fixture/enhanced-assertion-formatting.js rename to test-tap/fixture/enhanced-assertion-formatting.cjs diff --git a/test-tap/fixture/error-in-anonymous-function.js b/test-tap/fixture/error-in-anonymous-function.cjs similarity index 69% rename from test-tap/fixture/error-in-anonymous-function.js rename to test-tap/fixture/error-in-anonymous-function.cjs index b72330f11..bbdef8f9a 100644 --- a/test-tap/fixture/error-in-anonymous-function.js +++ b/test-tap/fixture/error-in-anonymous-function.cjs @@ -1,7 +1,7 @@ const test = require('../../entrypoints/main.cjs'); const getAnonymousFn = () => () => { - throw new Error(); + throw new Error(); // eslint-disable-line unicorn/error-message }; test('test', t => { diff --git a/test-tap/fixture/es2015.js b/test-tap/fixture/es2015.cjs similarity index 100% rename from test-tap/fixture/es2015.js rename to test-tap/fixture/es2015.cjs diff --git a/test-tap/fixture/eslint-plugin-helper/ava.config.js b/test-tap/fixture/eslint-plugin-helper/ava.config.mjs similarity index 100% rename from test-tap/fixture/eslint-plugin-helper/ava.config.js rename to test-tap/fixture/eslint-plugin-helper/ava.config.mjs diff --git a/test-tap/fixture/eslint-plugin-helper/for-overriding/ava.config.js b/test-tap/fixture/eslint-plugin-helper/for-overriding/ava.config.mjs similarity index 100% rename from test-tap/fixture/eslint-plugin-helper/for-overriding/ava.config.js rename to test-tap/fixture/eslint-plugin-helper/for-overriding/ava.config.mjs diff --git a/test-tap/fixture/fail-fast/crash/crashes.js b/test-tap/fixture/fail-fast/crash/crashes.cjs similarity index 100% rename from test-tap/fixture/fail-fast/crash/crashes.js rename to test-tap/fixture/fail-fast/crash/crashes.cjs diff --git a/test-tap/fixture/fail-fast/crash/passes.js b/test-tap/fixture/fail-fast/crash/passes.cjs similarity index 100% rename from test-tap/fixture/fail-fast/crash/passes.js rename to test-tap/fixture/fail-fast/crash/passes.cjs diff --git a/test-tap/fixture/fail-fast/multiple-files/fails.js b/test-tap/fixture/fail-fast/multiple-files/fails.cjs similarity index 100% rename from test-tap/fixture/fail-fast/multiple-files/fails.js rename to test-tap/fixture/fail-fast/multiple-files/fails.cjs diff --git a/test-tap/fixture/fail-fast/multiple-files/passes-slow.js b/test-tap/fixture/fail-fast/multiple-files/passes-slow.cjs similarity index 99% rename from test-tap/fixture/fail-fast/multiple-files/passes-slow.js rename to test-tap/fixture/fail-fast/multiple-files/passes-slow.cjs index e7c5a9bc4..9a36ab498 100644 --- a/test-tap/fixture/fail-fast/multiple-files/passes-slow.js +++ b/test-tap/fixture/fail-fast/multiple-files/passes-slow.cjs @@ -1,5 +1,7 @@ const {parentPort} = require('worker_threads'); + const pEvent = require('p-event'); + const test = require('../../../../entrypoints/main.cjs'); test.serial('first pass', async t => { diff --git a/test-tap/fixture/fail-fast/multiple-files/passes.js b/test-tap/fixture/fail-fast/multiple-files/passes.cjs similarity index 100% rename from test-tap/fixture/fail-fast/multiple-files/passes.js rename to test-tap/fixture/fail-fast/multiple-files/passes.cjs diff --git a/test-tap/fixture/fail-fast/single-file/test.js b/test-tap/fixture/fail-fast/single-file/test.cjs similarity index 100% rename from test-tap/fixture/fail-fast/single-file/test.js rename to test-tap/fixture/fail-fast/single-file/test.cjs diff --git a/test-tap/fixture/fail-fast/timeout/fails.js b/test-tap/fixture/fail-fast/timeout/fails.cjs similarity index 99% rename from test-tap/fixture/fail-fast/timeout/fails.js rename to test-tap/fixture/fail-fast/timeout/fails.cjs index 22cca4db2..e0996ab92 100644 --- a/test-tap/fixture/fail-fast/timeout/fails.js +++ b/test-tap/fixture/fail-fast/timeout/fails.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../../../entrypoints/main.cjs'); test('slow pass', async t => { diff --git a/test-tap/fixture/fail-fast/timeout/passes.js b/test-tap/fixture/fail-fast/timeout/passes.cjs similarity index 100% rename from test-tap/fixture/fail-fast/timeout/passes.js rename to test-tap/fixture/fail-fast/timeout/passes.cjs diff --git a/test-tap/fixture/fail-fast/without-error/a.js b/test-tap/fixture/fail-fast/without-error/a.cjs similarity index 100% rename from test-tap/fixture/fail-fast/without-error/a.js rename to test-tap/fixture/fail-fast/without-error/a.cjs diff --git a/test-tap/fixture/fail-fast/without-error/b.js b/test-tap/fixture/fail-fast/without-error/b.cjs similarity index 100% rename from test-tap/fixture/fail-fast/without-error/b.js rename to test-tap/fixture/fail-fast/without-error/b.cjs diff --git a/test-tap/fixture/formatting-color.js b/test-tap/fixture/formatting-color.cjs similarity index 100% rename from test-tap/fixture/formatting-color.js rename to test-tap/fixture/formatting-color.cjs diff --git a/test-tap/fixture/globs/custom-extension/test/do-not-compile.js b/test-tap/fixture/globs/custom-extension/test/do-not-compile.cjs similarity index 100% rename from test-tap/fixture/globs/custom-extension/test/do-not-compile.js rename to test-tap/fixture/globs/custom-extension/test/do-not-compile.cjs diff --git a/test-tap/fixture/globs/custom-extension/test/helpers/b.js b/test-tap/fixture/globs/custom-extension/test/helpers/b.cjs similarity index 100% rename from test-tap/fixture/globs/custom-extension/test/helpers/b.js rename to test-tap/fixture/globs/custom-extension/test/helpers/b.cjs diff --git a/test-tap/fixture/globs/cwd/dir-a/test/bar.js b/test-tap/fixture/globs/cwd/dir-a/test/bar.cjs similarity index 100% rename from test-tap/fixture/globs/cwd/dir-a/test/bar.js rename to test-tap/fixture/globs/cwd/dir-a/test/bar.cjs diff --git a/test-tap/fixture/globs/cwd/dir-a/test/foo.js b/test-tap/fixture/globs/cwd/dir-a/test/foo.cjs similarity index 100% rename from test-tap/fixture/globs/cwd/dir-a/test/foo.js rename to test-tap/fixture/globs/cwd/dir-a/test/foo.cjs diff --git a/test-tap/fixture/globs/cwd/dir-b/test/baz.js b/test-tap/fixture/globs/cwd/dir-b/test/baz.cjs similarity index 100% rename from test-tap/fixture/globs/cwd/dir-b/test/baz.js rename to test-tap/fixture/globs/cwd/dir-b/test/baz.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/_foo.js b/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/_foo.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/__tests__/_foo.js rename to test-tap/fixture/globs/default-patterns/sub/directory/__tests__/_foo.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/fixtures/foo.js b/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/fixtures/foo.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/__tests__/fixtures/foo.js rename to test-tap/fixture/globs/default-patterns/sub/directory/__tests__/fixtures/foo.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/foo.js b/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/foo.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/__tests__/foo.js rename to test-tap/fixture/globs/default-patterns/sub/directory/__tests__/foo.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/helpers/foo.js b/test-tap/fixture/globs/default-patterns/sub/directory/__tests__/helpers/foo.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/__tests__/helpers/foo.js rename to test-tap/fixture/globs/default-patterns/sub/directory/__tests__/helpers/foo.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/bar.spec.js b/test-tap/fixture/globs/default-patterns/sub/directory/bar.spec.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/bar.spec.js rename to test-tap/fixture/globs/default-patterns/sub/directory/bar.spec.cjs diff --git a/test-tap/fixture/globs/default-patterns/sub/directory/bar.test.js b/test-tap/fixture/globs/default-patterns/sub/directory/bar.test.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/sub/directory/bar.test.js rename to test-tap/fixture/globs/default-patterns/sub/directory/bar.test.cjs diff --git a/test-tap/fixture/globs/default-patterns/test-foo.js b/test-tap/fixture/globs/default-patterns/test-foo.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test-foo.js rename to test-tap/fixture/globs/default-patterns/test-foo.cjs diff --git a/test-tap/fixture/globs/default-patterns/test.js b/test-tap/fixture/globs/default-patterns/test.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test.js rename to test-tap/fixture/globs/default-patterns/test.cjs diff --git a/test-tap/fixture/globs/default-patterns/test/_foo-help.js b/test-tap/fixture/globs/default-patterns/test/_foo-help.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test/_foo-help.js rename to test-tap/fixture/globs/default-patterns/test/_foo-help.cjs diff --git a/test-tap/fixture/globs/default-patterns/test/baz.js b/test-tap/fixture/globs/default-patterns/test/baz.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test/baz.js rename to test-tap/fixture/globs/default-patterns/test/baz.cjs diff --git a/test-tap/fixture/globs/default-patterns/test/deep/deep.js b/test-tap/fixture/globs/default-patterns/test/deep/deep.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test/deep/deep.js rename to test-tap/fixture/globs/default-patterns/test/deep/deep.cjs diff --git a/test-tap/fixture/globs/default-patterns/test/fixtures/foo-fixt.js b/test-tap/fixture/globs/default-patterns/test/fixtures/foo-fixt.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test/fixtures/foo-fixt.js rename to test-tap/fixture/globs/default-patterns/test/fixtures/foo-fixt.cjs diff --git a/test-tap/fixture/globs/default-patterns/test/helpers/test.js b/test-tap/fixture/globs/default-patterns/test/helpers/test.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/test/helpers/test.js rename to test-tap/fixture/globs/default-patterns/test/helpers/test.cjs diff --git a/test-tap/fixture/globs/default-patterns/tests/_foo-help.js b/test-tap/fixture/globs/default-patterns/tests/_foo-help.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/tests/_foo-help.js rename to test-tap/fixture/globs/default-patterns/tests/_foo-help.cjs diff --git a/test-tap/fixture/globs/default-patterns/tests/baz.js b/test-tap/fixture/globs/default-patterns/tests/baz.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/tests/baz.js rename to test-tap/fixture/globs/default-patterns/tests/baz.cjs diff --git a/test-tap/fixture/globs/default-patterns/tests/deep/deep.js b/test-tap/fixture/globs/default-patterns/tests/deep/deep.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/tests/deep/deep.js rename to test-tap/fixture/globs/default-patterns/tests/deep/deep.cjs diff --git a/test-tap/fixture/globs/default-patterns/tests/fixtures/foo-fixt.js b/test-tap/fixture/globs/default-patterns/tests/fixtures/foo-fixt.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/tests/fixtures/foo-fixt.js rename to test-tap/fixture/globs/default-patterns/tests/fixtures/foo-fixt.cjs diff --git a/test-tap/fixture/globs/default-patterns/tests/helpers/test.js b/test-tap/fixture/globs/default-patterns/tests/helpers/test.cjs similarity index 100% rename from test-tap/fixture/globs/default-patterns/tests/helpers/test.js rename to test-tap/fixture/globs/default-patterns/tests/helpers/test.cjs diff --git a/test-tap/fixture/hooks-skipped.js b/test-tap/fixture/hooks-skipped.cjs similarity index 100% rename from test-tap/fixture/hooks-skipped.js rename to test-tap/fixture/hooks-skipped.cjs diff --git a/test-tap/fixture/ignored-dirs/helpers/test.js b/test-tap/fixture/ignored-dirs/helpers/test.cjs similarity index 100% rename from test-tap/fixture/ignored-dirs/helpers/test.js rename to test-tap/fixture/ignored-dirs/helpers/test.cjs diff --git a/test-tap/fixture/ignored-dirs/test.js b/test-tap/fixture/ignored-dirs/test.cjs similarity index 100% rename from test-tap/fixture/ignored-dirs/test.js rename to test-tap/fixture/ignored-dirs/test.cjs diff --git a/test-tap/fixture/improper-t-throws/caught-and-leaked-slowly.js b/test-tap/fixture/improper-t-throws/caught-and-leaked-slowly.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/caught-and-leaked-slowly.js rename to test-tap/fixture/improper-t-throws/caught-and-leaked-slowly.cjs diff --git a/test-tap/fixture/improper-t-throws/caught-and-leaked-too-slowly.js b/test-tap/fixture/improper-t-throws/caught-and-leaked-too-slowly.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/caught-and-leaked-too-slowly.js rename to test-tap/fixture/improper-t-throws/caught-and-leaked-too-slowly.cjs diff --git a/test-tap/fixture/improper-t-throws/caught-and-leaked.js b/test-tap/fixture/improper-t-throws/caught-and-leaked.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/caught-and-leaked.js rename to test-tap/fixture/improper-t-throws/caught-and-leaked.cjs diff --git a/test-tap/fixture/improper-t-throws/caught.js b/test-tap/fixture/improper-t-throws/caught.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/caught.js rename to test-tap/fixture/improper-t-throws/caught.cjs diff --git a/test-tap/fixture/improper-t-throws/leaked-from-promise.js b/test-tap/fixture/improper-t-throws/leaked-from-promise.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/leaked-from-promise.js rename to test-tap/fixture/improper-t-throws/leaked-from-promise.cjs diff --git a/test-tap/fixture/improper-t-throws/promise.js b/test-tap/fixture/improper-t-throws/promise.cjs similarity index 65% rename from test-tap/fixture/improper-t-throws/promise.js rename to test-tap/fixture/improper-t-throws/promise.cjs index cd9e40e7c..b2dfe327c 100644 --- a/test-tap/fixture/improper-t-throws/promise.js +++ b/test-tap/fixture/improper-t-throws/promise.cjs @@ -1,7 +1,7 @@ const test = require('../../../entrypoints/main.cjs'); test('test', t => { - return Promise.resolve().then(() => { + return Promise.resolve().then(() => { // eslint-disable-line promise/prefer-await-to-then t.throws(throwSync()); }); }); diff --git a/test-tap/fixture/improper-t-throws/throws.js b/test-tap/fixture/improper-t-throws/throws.cjs similarity index 100% rename from test-tap/fixture/improper-t-throws/throws.js rename to test-tap/fixture/improper-t-throws/throws.cjs diff --git a/test-tap/fixture/improper-t-throws/unhandled-rejection.js b/test-tap/fixture/improper-t-throws/unhandled-rejection.cjs similarity index 74% rename from test-tap/fixture/improper-t-throws/unhandled-rejection.js rename to test-tap/fixture/improper-t-throws/unhandled-rejection.cjs index 82e4fd2c4..80bc6d29d 100644 --- a/test-tap/fixture/improper-t-throws/unhandled-rejection.js +++ b/test-tap/fixture/improper-t-throws/unhandled-rejection.cjs @@ -1,8 +1,9 @@ const delay = require('delay'); + const test = require('../../../entrypoints/main.cjs'); test('test', async t => { - Promise.resolve().then(() => { + Promise.resolve().then(() => { // eslint-disable-line promise/prefer-await-to-then t.throws(throwSync()); }); diff --git a/test-tap/fixture/infinity-stack-trace.js b/test-tap/fixture/infinity-stack-trace.cjs similarity index 100% rename from test-tap/fixture/infinity-stack-trace.js rename to test-tap/fixture/infinity-stack-trace.cjs diff --git a/test-tap/fixture/install-global.js b/test-tap/fixture/install-global.cjs similarity index 100% rename from test-tap/fixture/install-global.js rename to test-tap/fixture/install-global.cjs diff --git a/test-tap/fixture/load-config/require/cjs.js b/test-tap/fixture/load-config/require/cjs.cjs similarity index 100% rename from test-tap/fixture/load-config/require/cjs.js rename to test-tap/fixture/load-config/require/cjs.cjs diff --git a/test-tap/fixture/long-running.js b/test-tap/fixture/long-running.cjs similarity index 99% rename from test-tap/fixture/long-running.js rename to test-tap/fixture/long-running.cjs index 8d93467f8..8fadb2184 100644 --- a/test-tap/fixture/long-running.js +++ b/test-tap/fixture/long-running.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../entrypoints/main.cjs'); test('slow', async t => { diff --git a/test-tap/fixture/match-no-match-2.js b/test-tap/fixture/match-no-match-2.cjs similarity index 100% rename from test-tap/fixture/match-no-match-2.js rename to test-tap/fixture/match-no-match-2.cjs diff --git a/test-tap/fixture/match-no-match.js b/test-tap/fixture/match-no-match.cjs similarity index 100% rename from test-tap/fixture/match-no-match.js rename to test-tap/fixture/match-no-match.cjs diff --git a/test-tap/fixture/matcher-skip.js b/test-tap/fixture/matcher-skip.cjs similarity index 100% rename from test-tap/fixture/matcher-skip.js rename to test-tap/fixture/matcher-skip.cjs diff --git a/test-tap/fixture/meta.js b/test-tap/fixture/meta.cjs similarity index 100% rename from test-tap/fixture/meta.js rename to test-tap/fixture/meta.cjs diff --git a/test-tap/fixture/no-tests.js b/test-tap/fixture/no-tests.cjs similarity index 100% rename from test-tap/fixture/no-tests.js rename to test-tap/fixture/no-tests.cjs diff --git a/test-tap/fixture/node-env-foo.js b/test-tap/fixture/node-env-foo.cjs similarity index 100% rename from test-tap/fixture/node-env-foo.js rename to test-tap/fixture/node-env-foo.cjs diff --git a/test-tap/fixture/node-env-test.js b/test-tap/fixture/node-env-test.cjs similarity index 100% rename from test-tap/fixture/node-env-test.js rename to test-tap/fixture/node-env-test.cjs diff --git a/test-tap/fixture/parallel-runs/less-files-than-ci-total/2.js b/test-tap/fixture/parallel-runs/less-files-than-ci-total/2.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/less-files-than-ci-total/2.js rename to test-tap/fixture/parallel-runs/less-files-than-ci-total/2.cjs diff --git a/test-tap/fixture/parallel-runs/less-files-than-ci-total/9.js b/test-tap/fixture/parallel-runs/less-files-than-ci-total/9.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/less-files-than-ci-total/9.js rename to test-tap/fixture/parallel-runs/less-files-than-ci-total/9.cjs diff --git a/test-tap/fixture/parallel-runs/less-files-than-ci-total/package.json b/test-tap/fixture/parallel-runs/less-files-than-ci-total/package.json index 0a8129b18..82a861884 100644 --- a/test-tap/fixture/parallel-runs/less-files-than-ci-total/package.json +++ b/test-tap/fixture/parallel-runs/less-files-than-ci-total/package.json @@ -1,5 +1,7 @@ { "ava": { - "files": ["*.js"] + "files": [ + "*.cjs" + ] } } diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/10.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/10.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/10.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/10.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/2.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/2.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/2.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/2.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/2a.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/2a.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/2a.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/2a.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/9.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/9.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/9.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/9.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/Ab.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/Ab.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/Ab.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/Ab.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/a.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/a.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/a.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/a.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/b.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/b.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/b.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/b.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/c.js b/test-tap/fixture/parallel-runs/more-files-than-ci-total/c.cjs similarity index 100% rename from test-tap/fixture/parallel-runs/more-files-than-ci-total/c.js rename to test-tap/fixture/parallel-runs/more-files-than-ci-total/c.cjs diff --git a/test-tap/fixture/parallel-runs/more-files-than-ci-total/package.json b/test-tap/fixture/parallel-runs/more-files-than-ci-total/package.json index 0a8129b18..82a861884 100644 --- a/test-tap/fixture/parallel-runs/more-files-than-ci-total/package.json +++ b/test-tap/fixture/parallel-runs/more-files-than-ci-total/package.json @@ -1,5 +1,7 @@ { "ava": { - "files": ["*.js"] + "files": [ + "*.cjs" + ] } } diff --git a/test-tap/fixture/parallel-runs/no-files/package.json b/test-tap/fixture/parallel-runs/no-files/package.json index 0a8129b18..82a861884 100644 --- a/test-tap/fixture/parallel-runs/no-files/package.json +++ b/test-tap/fixture/parallel-runs/no-files/package.json @@ -1,5 +1,7 @@ { "ava": { - "files": ["*.js"] + "files": [ + "*.cjs" + ] } } diff --git a/test-tap/fixture/pkg-conf/fail-without-assertions/test.js b/test-tap/fixture/pkg-conf/fail-without-assertions/test.cjs similarity index 100% rename from test-tap/fixture/pkg-conf/fail-without-assertions/test.js rename to test-tap/fixture/pkg-conf/fail-without-assertions/test.cjs diff --git a/test-tap/fixture/process-cwd-default.js b/test-tap/fixture/process-cwd-default.cjs similarity index 99% rename from test-tap/fixture/process-cwd-default.js rename to test-tap/fixture/process-cwd-default.cjs index dc5289400..bdb2504b2 100644 --- a/test-tap/fixture/process-cwd-default.js +++ b/test-tap/fixture/process-cwd-default.cjs @@ -1,5 +1,7 @@ const path = require('path'); + const pkgConf = require('pkg-conf'); + const test = require('../../entrypoints/main.cjs'); test('test', t => { diff --git a/test-tap/fixture/process-cwd-pkgdir.js b/test-tap/fixture/process-cwd-pkgdir.cjs similarity index 100% rename from test-tap/fixture/process-cwd-pkgdir.js rename to test-tap/fixture/process-cwd-pkgdir.cjs diff --git a/test-tap/fixture/report/edgecases/ast-syntax-error.js b/test-tap/fixture/report/edgecases/ast-syntax-error.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/ast-syntax-error.js rename to test-tap/fixture/report/edgecases/ast-syntax-error.cjs diff --git a/test-tap/fixture/report/edgecases/ava-import-no-test-declaration.js b/test-tap/fixture/report/edgecases/ava-import-no-test-declaration.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/ava-import-no-test-declaration.js rename to test-tap/fixture/report/edgecases/ava-import-no-test-declaration.cjs diff --git a/test-tap/fixture/report/edgecases/import-and-use-test-member.js b/test-tap/fixture/report/edgecases/import-and-use-test-member.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/import-and-use-test-member.js rename to test-tap/fixture/report/edgecases/import-and-use-test-member.cjs diff --git a/test-tap/fixture/report/edgecases/no-ava-import.js b/test-tap/fixture/report/edgecases/no-ava-import.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/no-ava-import.js rename to test-tap/fixture/report/edgecases/no-ava-import.cjs diff --git a/test-tap/fixture/report/edgecases/test.js b/test-tap/fixture/report/edgecases/test.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/test.js rename to test-tap/fixture/report/edgecases/test.cjs diff --git a/test-tap/fixture/report/edgecases/throws.js b/test-tap/fixture/report/edgecases/throws.cjs similarity index 100% rename from test-tap/fixture/report/edgecases/throws.js rename to test-tap/fixture/report/edgecases/throws.cjs diff --git a/test-tap/fixture/report/failfast/a.js b/test-tap/fixture/report/failfast/a.cjs similarity index 100% rename from test-tap/fixture/report/failfast/a.js rename to test-tap/fixture/report/failfast/a.cjs diff --git a/test-tap/fixture/report/failfast/b.js b/test-tap/fixture/report/failfast/b.cjs similarity index 100% rename from test-tap/fixture/report/failfast/b.js rename to test-tap/fixture/report/failfast/b.cjs diff --git a/test-tap/fixture/report/failfast2/a.js b/test-tap/fixture/report/failfast2/a.cjs similarity index 100% rename from test-tap/fixture/report/failfast2/a.js rename to test-tap/fixture/report/failfast2/a.cjs diff --git a/test-tap/fixture/report/failfast2/b.js b/test-tap/fixture/report/failfast2/b.cjs similarity index 100% rename from test-tap/fixture/report/failfast2/b.js rename to test-tap/fixture/report/failfast2/b.cjs diff --git a/test-tap/fixture/report/only/a.js b/test-tap/fixture/report/only/a.cjs similarity index 100% rename from test-tap/fixture/report/only/a.js rename to test-tap/fixture/report/only/a.cjs diff --git a/test-tap/fixture/report/only/b.js b/test-tap/fixture/report/only/b.cjs similarity index 100% rename from test-tap/fixture/report/only/b.js rename to test-tap/fixture/report/only/b.cjs diff --git a/test-tap/fixture/report/regular/bad-test-chain.js b/test-tap/fixture/report/regular/bad-test-chain.cjs similarity index 100% rename from test-tap/fixture/report/regular/bad-test-chain.js rename to test-tap/fixture/report/regular/bad-test-chain.cjs diff --git a/test-tap/fixture/report/regular/nested-objects.js b/test-tap/fixture/report/regular/nested-objects.cjs similarity index 99% rename from test-tap/fixture/report/regular/nested-objects.js rename to test-tap/fixture/report/regular/nested-objects.cjs index d92060377..defef6b55 100644 --- a/test-tap/fixture/report/regular/nested-objects.js +++ b/test-tap/fixture/report/regular/nested-objects.cjs @@ -1,6 +1,7 @@ -const test = require('../../../../entrypoints/main.cjs'); const util = require('util'); // eslint-disable-line unicorn/import-style +const test = require('../../../../entrypoints/main.cjs'); + util.inspect.defaultOptions.depth = 4; test('format with max depth 4', t => { diff --git a/test-tap/fixture/report/regular/output-in-hook.js b/test-tap/fixture/report/regular/output-in-hook.cjs similarity index 100% rename from test-tap/fixture/report/regular/output-in-hook.js rename to test-tap/fixture/report/regular/output-in-hook.cjs diff --git a/test-tap/fixture/report/regular/test.js b/test-tap/fixture/report/regular/test.cjs similarity index 95% rename from test-tap/fixture/report/regular/test.js rename to test-tap/fixture/report/regular/test.cjs index 62fe1fcc6..d28ba7e0a 100644 --- a/test-tap/fixture/report/regular/test.js +++ b/test-tap/fixture/report/regular/test.cjs @@ -44,6 +44,6 @@ test('bad notThrows', t => { }); test('implementation throws non-error', () => { - const err = null; - throw err; + const error = null; + throw error; }); diff --git a/test-tap/fixture/report/regular/traces-in-t-throws.js b/test-tap/fixture/report/regular/traces-in-t-throws.cjs similarity index 100% rename from test-tap/fixture/report/regular/traces-in-t-throws.js rename to test-tap/fixture/report/regular/traces-in-t-throws.cjs diff --git a/test-tap/fixture/report/regular/uncaught-exception.js b/test-tap/fixture/report/regular/uncaught-exception.cjs similarity index 100% rename from test-tap/fixture/report/regular/uncaught-exception.js rename to test-tap/fixture/report/regular/uncaught-exception.cjs diff --git a/test-tap/fixture/report/regular/unhandled-rejection.js b/test-tap/fixture/report/regular/unhandled-rejection.cjs similarity index 83% rename from test-tap/fixture/report/regular/unhandled-rejection.js rename to test-tap/fixture/report/regular/unhandled-rejection.cjs index 35fbd1c67..e3b1e5ef7 100644 --- a/test-tap/fixture/report/regular/unhandled-rejection.js +++ b/test-tap/fixture/report/regular/unhandled-rejection.cjs @@ -8,7 +8,7 @@ const passes = t => { test('passes', passes); test('unhandled non-error rejection', t => { - const err = null; - Promise.reject(err); + const error = null; + Promise.reject(error); t.pass(); }); diff --git a/test-tap/fixture/report/timeoutinmultiplefiles/a.js b/test-tap/fixture/report/timeoutinmultiplefiles/a.cjs similarity index 99% rename from test-tap/fixture/report/timeoutinmultiplefiles/a.js rename to test-tap/fixture/report/timeoutinmultiplefiles/a.cjs index 7e2d5e767..57247c9b9 100644 --- a/test-tap/fixture/report/timeoutinmultiplefiles/a.js +++ b/test-tap/fixture/report/timeoutinmultiplefiles/a.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../../../entrypoints/main.cjs'); test('a passes', t => t.pass()); diff --git a/test-tap/fixture/report/timeoutinmultiplefiles/b.js b/test-tap/fixture/report/timeoutinmultiplefiles/b.cjs similarity index 99% rename from test-tap/fixture/report/timeoutinmultiplefiles/b.js rename to test-tap/fixture/report/timeoutinmultiplefiles/b.cjs index 496828a7b..8919e7983 100644 --- a/test-tap/fixture/report/timeoutinmultiplefiles/b.js +++ b/test-tap/fixture/report/timeoutinmultiplefiles/b.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../../../entrypoints/main.cjs'); test('b passes', t => t.pass()); diff --git a/test-tap/fixture/report/timeoutinsinglefile/a.js b/test-tap/fixture/report/timeoutinsinglefile/a.cjs similarity index 99% rename from test-tap/fixture/report/timeoutinsinglefile/a.js rename to test-tap/fixture/report/timeoutinsinglefile/a.cjs index 10e96e26c..47aeafa0b 100644 --- a/test-tap/fixture/report/timeoutinsinglefile/a.js +++ b/test-tap/fixture/report/timeoutinsinglefile/a.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../../../entrypoints/main.cjs'); test('passes', t => t.pass()); diff --git a/test-tap/fixture/report/timeoutwithmatch/a.js b/test-tap/fixture/report/timeoutwithmatch/a.cjs similarity index 99% rename from test-tap/fixture/report/timeoutwithmatch/a.js rename to test-tap/fixture/report/timeoutwithmatch/a.cjs index fd2f9361f..85dfcde54 100644 --- a/test-tap/fixture/report/timeoutwithmatch/a.js +++ b/test-tap/fixture/report/timeoutwithmatch/a.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../../../entrypoints/main.cjs'); test('passes needle', t => t.pass()); diff --git a/test-tap/fixture/report/watch/test.js b/test-tap/fixture/report/watch/test.cjs similarity index 100% rename from test-tap/fixture/report/watch/test.js rename to test-tap/fixture/report/watch/test.cjs diff --git a/test-tap/fixture/reset-cache/test.js b/test-tap/fixture/reset-cache/test.cjs similarity index 100% rename from test-tap/fixture/reset-cache/test.js rename to test-tap/fixture/reset-cache/test.cjs diff --git a/test-tap/fixture/serial.js b/test-tap/fixture/serial.cjs similarity index 99% rename from test-tap/fixture/serial.js rename to test-tap/fixture/serial.cjs index 679b9d3a9..55847a06d 100644 --- a/test-tap/fixture/serial.js +++ b/test-tap/fixture/serial.cjs @@ -1,4 +1,5 @@ const delay = require('delay'); + const test = require('../../entrypoints/main.cjs'); const tests = []; diff --git a/test-tap/fixture/skip-only.js b/test-tap/fixture/skip-only.cjs similarity index 100% rename from test-tap/fixture/skip-only.js rename to test-tap/fixture/skip-only.cjs diff --git a/test-tap/fixture/snapshots/__tests__-dir/__tests__/test.js b/test-tap/fixture/snapshots/__tests__-dir/__tests__/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/__tests__-dir/__tests__/test.js rename to test-tap/fixture/snapshots/__tests__-dir/__tests__/test.cjs diff --git a/test-tap/fixture/snapshots/test-content/package.json b/test-tap/fixture/snapshots/test-content/package.json index 7a403aaa7..4b1c5e66f 100644 --- a/test-tap/fixture/snapshots/test-content/package.json +++ b/test-tap/fixture/snapshots/test-content/package.json @@ -1,5 +1,7 @@ { "ava": { - "files": ["tests/test.js"] + "files": [ + "tests/test.cjs" + ] } } diff --git a/test-tap/fixture/snapshots/test-content/test.js.md.expected b/test-tap/fixture/snapshots/test-content/test.cjs.md.expected similarity index 53% rename from test-tap/fixture/snapshots/test-content/test.js.md.expected rename to test-tap/fixture/snapshots/test-content/test.cjs.md.expected index 677e9fc31..c867d3fe6 100644 --- a/test-tap/fixture/snapshots/test-content/test.js.md.expected +++ b/test-tap/fixture/snapshots/test-content/test.cjs.md.expected @@ -1,6 +1,6 @@ -# Snapshot report for `tests/test.js` +# Snapshot report for `tests/test.cjs` -The actual snapshot is saved in `test.js.snap`. +The actual snapshot is saved in `test.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/test-tap/fixture/snapshots/test-content/test.js.snap.expected b/test-tap/fixture/snapshots/test-content/test.cjs.snap.expected similarity index 100% rename from test-tap/fixture/snapshots/test-content/test.js.snap.expected rename to test-tap/fixture/snapshots/test-content/test.cjs.snap.expected diff --git a/test-tap/fixture/snapshots/test-content/tests/test.js b/test-tap/fixture/snapshots/test-content/tests/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test-content/tests/test.js rename to test-tap/fixture/snapshots/test-content/tests/test.cjs diff --git a/test-tap/fixture/snapshots/test-dir/test/test.js b/test-tap/fixture/snapshots/test-dir/test/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test-dir/test/test.js rename to test-tap/fixture/snapshots/test-dir/test/test.cjs diff --git a/test-tap/fixture/snapshots/test-snapshot-location/package.json b/test-tap/fixture/snapshots/test-snapshot-location/package.json index 1d09ac4fc..213c6f91c 100644 --- a/test-tap/fixture/snapshots/test-snapshot-location/package.json +++ b/test-tap/fixture/snapshots/test-snapshot-location/package.json @@ -1,7 +1,7 @@ { "ava": { "files": [ - "src/**/*test.js" + "src/**/*test.cjs" ], "snapshotDir": "snapshot-fixtures" } diff --git a/test-tap/fixture/snapshots/test-snapshot-location/src/feature/nested-feature/test.js b/test-tap/fixture/snapshots/test-snapshot-location/src/feature/nested-feature/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test-snapshot-location/src/feature/nested-feature/test.js rename to test-tap/fixture/snapshots/test-snapshot-location/src/feature/nested-feature/test.cjs diff --git a/test-tap/fixture/snapshots/test-snapshot-location/src/feature/test.js b/test-tap/fixture/snapshots/test-snapshot-location/src/feature/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test-snapshot-location/src/feature/test.js rename to test-tap/fixture/snapshots/test-snapshot-location/src/feature/test.cjs diff --git a/test-tap/fixture/snapshots/test-snapshot-location/src/test.js b/test-tap/fixture/snapshots/test-snapshot-location/src/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test-snapshot-location/src/test.js rename to test-tap/fixture/snapshots/test-snapshot-location/src/test.cjs diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js b/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs similarity index 87% rename from test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js rename to test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs index 2c2cbeff5..eb4c73961 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs @@ -6,4 +6,4 @@ test('feature test title', t => { test('another feature test', t => { t.snapshot(new Map()); }); -//# sourceMappingURL=test.js.map +//# sourceMappingURL=test.cjs.map diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs.map b/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs.map new file mode 100644 index 000000000..b23f4c760 --- /dev/null +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.cjs.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "test.cjs", + "sourceRoot": "", + "sources": [ + "../../../src/feature/__tests__/test.ts" + ], + "names": [], + "mappings": "AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAA;AAEvC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC3B,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC7B,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC" +} diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js.map b/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js.map deleted file mode 100644 index 8eb33e38c..000000000 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/feature/__tests__/test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test.js","sourceRoot":"","sources":["../../../src/feature/__tests__/test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,sBAAsB,CAAA;AAEvC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC3B,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC7B,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test.js b/test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs similarity index 87% rename from test-tap/fixture/snapshots/test-sourcemaps/build/test.js rename to test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs index 96dfdb234..1b021029a 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/test.js +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs @@ -6,4 +6,4 @@ test('top level test title', t => { test('another top level test', t => { t.snapshot(new Map()); }); -//# sourceMappingURL=test.js.map +//# sourceMappingURL=test.cjs.map diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs.map b/test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs.map new file mode 100644 index 000000000..0d22b0298 --- /dev/null +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/test.cjs.map @@ -0,0 +1 @@ +{"version":3,"file":"test.cjs","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC7B,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAC/B,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"} diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test.js.map b/test-tap/fixture/snapshots/test-sourcemaps/build/test.js.map deleted file mode 100644 index c836afc79..000000000 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC7B,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAC/B,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js b/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs similarity index 86% rename from test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js rename to test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs index 3fa218757..68d51ed13 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs @@ -6,4 +6,4 @@ test('test title', t => { test('another test', t => { t.snapshot(new Map()); }); -//# sourceMappingURL=test.js.map +//# sourceMappingURL=test.cjs.map diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs.map b/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs.map new file mode 100644 index 000000000..fb3e432db --- /dev/null +++ b/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.cjs.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "test.cjs", + "sourceRoot": "", + "sources": [ + "../../src/test/test.ts" + ], + "names": [], + "mappings": "AAAA,OAAO,IAAI,MAAM,mBAAmB,CAAC;AAErC,IAAI,CAAC,YAAY,EAAE,CAAC;IACnB,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,cAAc,EAAE,CAAC;IACrB,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC" +} diff --git a/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js.map b/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js.map deleted file mode 100644 index a707fe49c..000000000 --- a/test-tap/fixture/snapshots/test-sourcemaps/build/test/test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test/test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,mBAAmB,CAAC;AAErC,IAAI,CAAC,YAAY,EAAE,CAAC;IACnB,CAAC,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,EAAC,MAAM,EAAE,EAAE,EAAC,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,cAAc,EAAE,CAAC;IACrB,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test-tap/fixture/snapshots/test-sourcemaps/package.json b/test-tap/fixture/snapshots/test-sourcemaps/package.json index 56e413658..088edf495 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/package.json +++ b/test-tap/fixture/snapshots/test-sourcemaps/package.json @@ -1,7 +1,7 @@ { "ava": { "files": [ - "build/**/test.js" + "build/**/test.cjs" ] } } diff --git a/test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts b/test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts index 39d1c2dc6..859d3890d 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts +++ b/test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts @@ -1,4 +1,4 @@ -const test = require('../../../../../../../entrypoints/main.cjs'); +import test from '../../../../../../../entrypoints/main.cjs'; test('feature test title', t => { t.snapshot({foo: 'bar'}); diff --git a/test-tap/fixture/snapshots/test-sourcemaps/src/test.ts b/test-tap/fixture/snapshots/test-sourcemaps/src/test.ts index 63b03cf62..17d6155d1 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/src/test.ts +++ b/test-tap/fixture/snapshots/test-sourcemaps/src/test.ts @@ -1,4 +1,4 @@ -const test = require('../../../../../entrypoints/main.cjs'); +import test from '../../../../../entrypoints/main.cjs'; test('top level test title', t => { t.snapshot({foo: 'bar'}); diff --git a/test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts b/test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts index ea555517e..d265daf43 100644 --- a/test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts +++ b/test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts @@ -1,4 +1,4 @@ -const test = require('../../../../../../entrypoints/main.cjs'); +import test from '../../../../../../entrypoints/main.cjs'; test('test title', t => { t.snapshot({foo: 'bar'}); diff --git a/test-tap/fixture/snapshots/test.js b/test-tap/fixture/snapshots/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/test.js rename to test-tap/fixture/snapshots/test.cjs diff --git a/test-tap/fixture/snapshots/tests-dir/package.json b/test-tap/fixture/snapshots/tests-dir/package.json index 101d85b3c..b3747dcca 100644 --- a/test-tap/fixture/snapshots/tests-dir/package.json +++ b/test-tap/fixture/snapshots/tests-dir/package.json @@ -1,5 +1,7 @@ { "ava": { - "files": ["tests/**/*.js"] + "files": [ + "tests/**/*.cjs" + ] } } diff --git a/test-tap/fixture/snapshots/tests-dir/tests/test.js b/test-tap/fixture/snapshots/tests-dir/tests/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/tests-dir/tests/test.js rename to test-tap/fixture/snapshots/tests-dir/tests/test.cjs diff --git a/test-tap/fixture/snapshots/watcher-rerun-unlink/test.js b/test-tap/fixture/snapshots/watcher-rerun-unlink/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/watcher-rerun-unlink/test.js rename to test-tap/fixture/snapshots/watcher-rerun-unlink/test.cjs diff --git a/test-tap/fixture/snapshots/watcher-rerun/test.js b/test-tap/fixture/snapshots/watcher-rerun/test.cjs similarity index 100% rename from test-tap/fixture/snapshots/watcher-rerun/test.js rename to test-tap/fixture/snapshots/watcher-rerun/test.cjs diff --git a/test-tap/fixture/source-map-file-browser-env.js b/test-tap/fixture/source-map-file-browser-env.cjs similarity index 99% rename from test-tap/fixture/source-map-file-browser-env.js rename to test-tap/fixture/source-map-file-browser-env.cjs index 7a17ff21d..0997318ef 100644 --- a/test-tap/fixture/source-map-file-browser-env.js +++ b/test-tap/fixture/source-map-file-browser-env.cjs @@ -1,4 +1,5 @@ const fixture = require('source-map-fixtures').mapFile('throws').require(); + const test = require('../../entrypoints/main.cjs'); global.window = function () {}; diff --git a/test-tap/fixture/source-map-file.js b/test-tap/fixture/source-map-file.cjs similarity index 99% rename from test-tap/fixture/source-map-file.js rename to test-tap/fixture/source-map-file.cjs index 2a74be551..e1254a327 100644 --- a/test-tap/fixture/source-map-file.js +++ b/test-tap/fixture/source-map-file.cjs @@ -1,4 +1,5 @@ const fixture = require('source-map-fixtures').mapFile('throws').require(); + const test = require('../../entrypoints/main.cjs'); const run = () => fixture.run(); diff --git a/test-tap/fixture/source-map-initial.js b/test-tap/fixture/source-map-initial.cjs similarity index 62% rename from test-tap/fixture/source-map-initial.js rename to test-tap/fixture/source-map-initial.cjs index 60e7290b1..8e9022163 100644 --- a/test-tap/fixture/source-map-initial.js +++ b/test-tap/fixture/source-map-initial.cjs @@ -1,12 +1,14 @@ 'use strict'; -var _sourceMapFixtures = require('source-map-fixtures'); +const _sourceMapFixtures = require('source-map-fixtures'); -var _ = require('../../entrypoints/main.cjs'); +const _ = require('../../entrypoints/main.cjs'); -var _2 = _interopRequireDefault(_); +const _2 = _interopRequireDefault(_); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(object) { + return object && object.__esModule ? object : {default: object}; +} const fixture = (0, _sourceMapFixtures.mapFile)('throws').require(); @@ -19,5 +21,5 @@ const fixture = (0, _sourceMapFixtures.mapFile)('throws').require(); t.pass(); }); const run = () => fixture.run(); -//# sourceMappingURL=./source-map-initial.js.map -// Generated using node test/fixtures/_generate-source-map-initial.js +// # sourceMappingURL=./source-map-initial.cjs.map +// Generated using node test/fixtures/_generate-source-map-initial.cjs diff --git a/test-tap/fixture/source-map-initial.cjs.map b/test-tap/fixture/source-map-initial.cjs.map new file mode 100644 index 000000000..d12048094 --- /dev/null +++ b/test-tap/fixture/source-map-initial.cjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["source-map-initial-input.cjs"],"names":["fixture","require","t","setImmediate","run","pass"],"mappings":";;AAAA;;AACA;;;;;;AAEA,MAAMA,UAAU,gCAAQ,QAAR,EAAkBC,OAAlB,EAAhB;;AAEA;AACA;AACA;AACA;AACA,gBAAK,6BAAL,EAAoCC,KAAK;AACxCC,cAAaC,GAAb;AACAF,GAAEG,IAAF;AACA,CAHD;AAIA,MAAMD,MAAM,MAAMJ,QAAQI,GAAR,EAAlB","file":"source-map-initial-input.js","sourcesContent":["import {mapFile} from 'source-map-fixtures';\nimport test from '../../';\n\nconst fixture = mapFile('throws').require();\n\n// The uncaught exception is passed to the corresponding cli test. The line\n// numbers from the 'throws' fixture (which uses a map file), as well as the\n// line of the fixture.run() call, should match the source lines from this\n// string.\ntest('throw an uncaught exception', t => {\n\tsetImmediate(run);\n\tt.pass();\n})\nconst run = () => fixture.run();"]} diff --git a/test-tap/fixture/source-map-initial.js.map b/test-tap/fixture/source-map-initial.js.map deleted file mode 100644 index 9f092b861..000000000 --- a/test-tap/fixture/source-map-initial.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["source-map-initial-input.js"],"names":["fixture","require","t","setImmediate","run","pass"],"mappings":";;AAAA;;AACA;;;;;;AAEA,MAAMA,UAAU,gCAAQ,QAAR,EAAkBC,OAAlB,EAAhB;;AAEA;AACA;AACA;AACA;AACA,gBAAK,6BAAL,EAAoCC,KAAK;AACxCC,cAAaC,GAAb;AACAF,GAAEG,IAAF;AACA,CAHD;AAIA,MAAMD,MAAM,MAAMJ,QAAQI,GAAR,EAAlB","file":"source-map-initial-input.js","sourcesContent":["import {mapFile} from 'source-map-fixtures';\nimport test from '../../';\n\nconst fixture = mapFile('throws').require();\n\n// The uncaught exception is passed to the corresponding cli test. The line\n// numbers from the 'throws' fixture (which uses a map file), as well as the\n// line of the fixture.run() call, should match the source lines from this\n// string.\ntest('throw an uncaught exception', t => {\n\tsetImmediate(run);\n\tt.pass();\n})\nconst run = () => fixture.run();"]} \ No newline at end of file diff --git a/test-tap/fixture/source-map-inline.js b/test-tap/fixture/source-map-inline.cjs similarity index 99% rename from test-tap/fixture/source-map-inline.js rename to test-tap/fixture/source-map-inline.cjs index aed99dfaa..593237ad3 100644 --- a/test-tap/fixture/source-map-inline.js +++ b/test-tap/fixture/source-map-inline.cjs @@ -1,4 +1,5 @@ const fixture = require('source-map-fixtures').inline('throws').require(); + const test = require('../../entrypoints/main.cjs'); const run = () => fixture.run(); diff --git a/test-tap/fixture/source-with-source-map-pragma.js b/test-tap/fixture/source-with-source-map-pragma.cjs similarity index 100% rename from test-tap/fixture/source-with-source-map-pragma.js rename to test-tap/fixture/source-with-source-map-pragma.cjs diff --git a/test-tap/fixture/stalled-tests/observable.js b/test-tap/fixture/stalled-tests/observable.cjs similarity index 99% rename from test-tap/fixture/stalled-tests/observable.js rename to test-tap/fixture/stalled-tests/observable.cjs index 02ac4e350..f1ba152ab 100644 --- a/test-tap/fixture/stalled-tests/observable.js +++ b/test-tap/fixture/stalled-tests/observable.cjs @@ -1,4 +1,5 @@ const Observable = require('zen-observable'); + const test = require('../../../entrypoints/main.cjs'); test('test', t => { diff --git a/test-tap/fixture/stalled-tests/promise.js b/test-tap/fixture/stalled-tests/promise.cjs similarity index 100% rename from test-tap/fixture/stalled-tests/promise.js rename to test-tap/fixture/stalled-tests/promise.cjs diff --git a/test-tap/fixture/symlinkdir/symlink.js b/test-tap/fixture/symlinkdir/symlink.cjs similarity index 100% rename from test-tap/fixture/symlinkdir/symlink.js rename to test-tap/fixture/symlinkdir/symlink.cjs diff --git a/test-tap/fixture/symlinkfile.cjs b/test-tap/fixture/symlinkfile.cjs new file mode 120000 index 000000000..eb469079c --- /dev/null +++ b/test-tap/fixture/symlinkfile.cjs @@ -0,0 +1 @@ +target-symlink.cjs \ No newline at end of file diff --git a/test-tap/fixture/symlinkfile.js b/test-tap/fixture/symlinkfile.js deleted file mode 120000 index 05c6ccb6e..000000000 --- a/test-tap/fixture/symlinkfile.js +++ /dev/null @@ -1 +0,0 @@ -./target-symlink.js \ No newline at end of file diff --git a/test-tap/fixture/target-symlink.js b/test-tap/fixture/target-symlink.cjs similarity index 100% rename from test-tap/fixture/target-symlink.js rename to test-tap/fixture/target-symlink.cjs diff --git a/test-tap/fixture/test-count-2.js b/test-tap/fixture/test-count-2.cjs similarity index 100% rename from test-tap/fixture/test-count-2.js rename to test-tap/fixture/test-count-2.cjs diff --git a/test-tap/fixture/test-count-3.js b/test-tap/fixture/test-count-3.cjs similarity index 100% rename from test-tap/fixture/test-count-3.js rename to test-tap/fixture/test-count-3.cjs diff --git a/test-tap/fixture/test-count.js b/test-tap/fixture/test-count.cjs similarity index 100% rename from test-tap/fixture/test-count.js rename to test-tap/fixture/test-count.cjs diff --git a/test-tap/fixture/try-snapshot.js.md b/test-tap/fixture/try-snapshot.cjs.md similarity index 75% rename from test-tap/fixture/try-snapshot.js.md rename to test-tap/fixture/try-snapshot.cjs.md index 2ceb2c743..9098f82d2 100644 --- a/test-tap/fixture/try-snapshot.js.md +++ b/test-tap/fixture/try-snapshot.cjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `try-snapshot.js` +# Snapshot report for `try-snapshot.cjs` -The actual snapshot is saved in `try-snapshot.js.snap`. +The actual snapshot is saved in `try-snapshot.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/test-tap/fixture/try-snapshot.js.snap b/test-tap/fixture/try-snapshot.cjs.snap similarity index 100% rename from test-tap/fixture/try-snapshot.js.snap rename to test-tap/fixture/try-snapshot.cjs.snap diff --git a/test-tap/fixture/validate-installed-global.js b/test-tap/fixture/validate-installed-global.cjs similarity index 100% rename from test-tap/fixture/validate-installed-global.js rename to test-tap/fixture/validate-installed-global.cjs diff --git a/test-tap/fixture/watcher/ignored-files/ignore.js b/test-tap/fixture/watcher/ignored-files/ignore.cjs similarity index 100% rename from test-tap/fixture/watcher/ignored-files/ignore.js rename to test-tap/fixture/watcher/ignored-files/ignore.cjs diff --git a/test-tap/fixture/watcher/ignored-files/ignored.js b/test-tap/fixture/watcher/ignored-files/ignored.cjs similarity index 100% rename from test-tap/fixture/watcher/ignored-files/ignored.js rename to test-tap/fixture/watcher/ignored-files/ignored.cjs diff --git a/test-tap/fixture/watcher/ignored-files/package.json b/test-tap/fixture/watcher/ignored-files/package.json index 69b580238..a0358103a 100644 --- a/test-tap/fixture/watcher/ignored-files/package.json +++ b/test-tap/fixture/watcher/ignored-files/package.json @@ -1,6 +1,10 @@ { "ava": { - "files": ["test.js"], - "ignoredByWatcher": ["ignored.js"] + "files": [ + "test.cjs" + ], + "ignoredByWatcher": [ + "ignored.cjs" + ] } } diff --git a/test-tap/fixture/watcher/ignored-files/source.js b/test-tap/fixture/watcher/ignored-files/source.cjs similarity index 100% rename from test-tap/fixture/watcher/ignored-files/source.js rename to test-tap/fixture/watcher/ignored-files/source.cjs diff --git a/test-tap/fixture/watcher/ignored-files/test.js b/test-tap/fixture/watcher/ignored-files/test.cjs similarity index 100% rename from test-tap/fixture/watcher/ignored-files/test.js rename to test-tap/fixture/watcher/ignored-files/test.cjs diff --git a/test-tap/fixture/watcher/tap-in-conf/test.js b/test-tap/fixture/watcher/tap-in-conf/test.cjs similarity index 100% rename from test-tap/fixture/watcher/tap-in-conf/test.js rename to test-tap/fixture/watcher/tap-in-conf/test.cjs diff --git a/test-tap/fixture/watcher/test.js b/test-tap/fixture/watcher/test.cjs similarity index 100% rename from test-tap/fixture/watcher/test.js rename to test-tap/fixture/watcher/test.cjs diff --git a/test-tap/fixture/watcher/with-dependencies/source.js b/test-tap/fixture/watcher/with-dependencies/source.cjs similarity index 100% rename from test-tap/fixture/watcher/with-dependencies/source.js rename to test-tap/fixture/watcher/with-dependencies/source.cjs diff --git a/test-tap/fixture/watcher/with-dependencies/test-1.js b/test-tap/fixture/watcher/with-dependencies/test-1.cjs similarity index 99% rename from test-tap/fixture/watcher/with-dependencies/test-1.js rename to test-tap/fixture/watcher/with-dependencies/test-1.cjs index c3dfdaee7..ee277d37e 100644 --- a/test-tap/fixture/watcher/with-dependencies/test-1.js +++ b/test-tap/fixture/watcher/with-dependencies/test-1.cjs @@ -1,4 +1,5 @@ const test = require('../../../../entrypoints/main.cjs'); + const dependency = require('./source'); test('works', t => { diff --git a/test-tap/fixture/watcher/with-dependencies/test-2.js b/test-tap/fixture/watcher/with-dependencies/test-2.cjs similarity index 100% rename from test-tap/fixture/watcher/with-dependencies/test-2.js rename to test-tap/fixture/watcher/with-dependencies/test-2.cjs diff --git a/test-tap/fixture/with-dependencies/no-tests.js b/test-tap/fixture/with-dependencies/no-tests.cjs similarity index 100% rename from test-tap/fixture/with-dependencies/no-tests.js rename to test-tap/fixture/with-dependencies/no-tests.cjs diff --git a/test-tap/fixture/with-dependencies/require-custom.js b/test-tap/fixture/with-dependencies/require-custom.cjs similarity index 100% rename from test-tap/fixture/with-dependencies/require-custom.js rename to test-tap/fixture/with-dependencies/require-custom.cjs diff --git a/test-tap/fixture/with-dependencies/test-failure.js b/test-tap/fixture/with-dependencies/test-failure.cjs similarity index 100% rename from test-tap/fixture/with-dependencies/test-failure.js rename to test-tap/fixture/with-dependencies/test-failure.cjs diff --git a/test-tap/fixture/with-dependencies/test-uncaught-exception.js b/test-tap/fixture/with-dependencies/test-uncaught-exception.cjs similarity index 100% rename from test-tap/fixture/with-dependencies/test-uncaught-exception.js rename to test-tap/fixture/with-dependencies/test-uncaught-exception.cjs diff --git a/test-tap/fixture/with-dependencies/test.js b/test-tap/fixture/with-dependencies/test.cjs similarity index 100% rename from test-tap/fixture/with-dependencies/test.js rename to test-tap/fixture/with-dependencies/test.cjs diff --git a/test-tap/fixture/worker-argv.js b/test-tap/fixture/worker-argv.cjs similarity index 100% rename from test-tap/fixture/worker-argv.js rename to test-tap/fixture/worker-argv.cjs diff --git a/test-tap/globs.js b/test-tap/globs.js index 2620ac7de..de789a6ae 100644 --- a/test-tap/globs.js +++ b/test-tap/globs.js @@ -1,10 +1,14 @@ -'use strict'; -const path = require('path'); -const tap = require('tap'); -const globs = require('../lib/globs'); +import path from 'path'; +import {fileURLToPath} from 'url'; + +import tap from 'tap'; + +import * as globs from '../lib/globs.js'; const {test} = tap; +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + tap.afterEach(() => { // We changed the CWD in some of the tests process.chdir(path.resolve(__dirname, '..')); @@ -286,39 +290,39 @@ test('isIgnoredByWatcher after provider modifications', t => { t.end(); }); -test('findFiles finds non-ignored files (just .js)', async t => { +test('findFiles finds non-ignored files (just .cjs)', async t => { const fixtureDir = fixture('default-patterns'); process.chdir(fixtureDir); const expected = [ - 'sub/directory/__tests__/_foo.js', - 'sub/directory/__tests__/foo.js', - 'sub/directory/bar.spec.js', - 'sub/directory/bar.test.js', - 'test-foo.js', - 'test.js', - 'test/_foo-help.js', - 'test/baz.js', - 'test/deep/deep.js', - 'tests/baz.js', - 'tests/deep/deep.js', - 'tests/_foo-help.js' + 'sub/directory/__tests__/_foo.cjs', + 'sub/directory/__tests__/foo.cjs', + 'sub/directory/bar.spec.cjs', + 'sub/directory/bar.test.cjs', + 'test-foo.cjs', + 'test.cjs', + 'test/_foo-help.cjs', + 'test/baz.cjs', + 'test/deep/deep.cjs', + 'tests/baz.cjs', + 'tests/deep/deep.cjs', + 'tests/_foo-help.cjs' ].map(file => path.join(fixtureDir, file)).sort(); const actual = await globs.findFiles({ cwd: fixtureDir, - ...globs.normalizeGlobs({files: ['!**/fixtures/*.*', '!**/helpers/*.*'], extensions: ['js'], providers: []}) + ...globs.normalizeGlobs({files: ['!**/fixtures/*.*', '!**/helpers/*.*'], extensions: ['cjs'], providers: []}) }); actual.sort(); t.same(actual, expected); }); -test('findFiles finds non-ignored files (.js, .jsx)', async t => { +test('findFiles finds non-ignored files (.cjs, .jsx)', async t => { const fixtureDir = fixture('custom-extension'); process.chdir(fixtureDir); const expected = [ - 'test/do-not-compile.js', + 'test/do-not-compile.cjs', 'test/foo.jsx', 'test/sub/_helper.jsx', 'test/sub/bar.jsx' @@ -326,7 +330,7 @@ test('findFiles finds non-ignored files (.js, .jsx)', async t => { const actual = await globs.findFiles({ cwd: fixtureDir, - ...globs.normalizeGlobs({files: ['!**/fixtures/*', '!**/helpers/*'], extensions: ['js', 'jsx'], providers: []}) + ...globs.normalizeGlobs({files: ['!**/fixtures/*', '!**/helpers/*'], extensions: ['cjs', 'jsx'], providers: []}) }); actual.sort(); t.same(actual, expected); diff --git a/test-tap/helper/ava-test.js b/test-tap/helper/ava-test.js index fafa4701a..3e3ef13c1 100644 --- a/test-tap/helper/ava-test.js +++ b/test-tap/helper/ava-test.js @@ -1,7 +1,7 @@ -const Test = require('../../lib/test'); -const ContextRef = require('../../lib/context-ref'); +import ContextRef from '../../lib/context-ref.js'; +import Test from '../../lib/test.js'; -function withExperiments(experiments = {}) { +export function withExperiments(experiments = {}) { const uniqueTestTitles = new Set(); const registerUniqueTitle = title => { if (uniqueTestTitles.has(title)) { @@ -39,6 +39,5 @@ function withExperiments(experiments = {}) { return ava; } -exports.ava = withExperiments(); -exports.withExperiments = withExperiments; -exports.newAva = () => withExperiments(); +export const ava = withExperiments(); +export const newAva = () => withExperiments(); diff --git a/test-tap/helper/chalk0.js b/test-tap/helper/chalk0.js new file mode 100644 index 000000000..6096bbce9 --- /dev/null +++ b/test-tap/helper/chalk0.js @@ -0,0 +1,3 @@ +import {set as setChalk} from '../../lib/chalk.js'; + +setChalk({level: 0}); diff --git a/test-tap/helper/cli.js b/test-tap/helper/cli.js index df540126e..45f03c460 100644 --- a/test-tap/helper/cli.js +++ b/test-tap/helper/cli.js @@ -1,11 +1,13 @@ -'use strict'; -const path = require('path'); -const childProcess = require('child_process'); -const getStream = require('get-stream'); +import childProcess from 'child_process'; +import path from 'path'; +import {fileURLToPath} from 'url'; -const cliPath = path.join(__dirname, '../../entrypoints/cli.mjs'); +import getStream from 'get-stream'; -function execCli(args, options, cb) { +const __dirname = fileURLToPath(new URL('.', import.meta.url)); +const cliPath = fileURLToPath(new URL('../../entrypoints/cli.mjs', import.meta.url)); + +export function execCli(args, options, cb) { let dirname; let env; @@ -52,5 +54,3 @@ function execCli(args, options, cb) { return child; } - -exports.execCli = execCli; diff --git a/test-tap/helper/fix-reporter-env.js b/test-tap/helper/fix-reporter-env.js index a40f37f40..177187d24 100644 --- a/test-tap/helper/fix-reporter-env.js +++ b/test-tap/helper/fix-reporter-env.js @@ -1,6 +1,8 @@ -'use strict'; -const os = require('os'); -const fakeTimers = require('@sinonjs/fake-timers'); +import os from 'os'; + +import fakeTimers from '@sinonjs/fake-timers'; + +import {set as setChalk} from '../../lib/chalk.js'; const fixColors = () => { // Force consistent and high-fidelity logs. @@ -8,7 +10,7 @@ const fixColors = () => { Object.defineProperty(process, 'platform', {value: 'darwin', enumerable: true, configurable: true}); }; -module.exports = () => { +export default () => { // Fix timestamps. const clock = fakeTimers.install({ now: new Date(2014, 11, 19, 17, 19, 12, 200).getTime(), @@ -21,7 +23,7 @@ module.exports = () => { Object.defineProperty(os, 'EOL', {value: '\n'}); fixColors(); - require('../../lib/chalk').set({level: 3}); + setChalk({level: 3}); return { restoreClock() { @@ -30,4 +32,4 @@ module.exports = () => { }; }; -module.exports.onlyColors = fixColors; +export {fixColors as onlyColors}; diff --git a/test-tap/helper/replay-report.js b/test-tap/helper/replay-report.js index 7dcded75b..78db323bb 100755 --- a/test-tap/helper/replay-report.js +++ b/test-tap/helper/replay-report.js @@ -1,8 +1,9 @@ #!/usr/bin/env node -'use strict'; -const fs = require('fs'); -const delay = require('delay'); -const TTYStream = require('./tty-stream'); +import fs from 'fs'; + +import delay from 'delay'; + +import TTYStream from './tty-stream.js'; const lines = fs.readFileSync(process.argv[2], 'utf8').split(TTYStream.SEPARATOR.toString('utf8')); diff --git a/test-tap/helper/report-worker.js b/test-tap/helper/report-worker.js index c7b708ca3..4c14ecd75 100644 --- a/test-tap/helper/report-worker.js +++ b/test-tap/helper/report-worker.js @@ -1,3 +1,4 @@ -'use strict'; -require('./fix-reporter-env').onlyColors(); -require('../../lib/worker/base'); // eslint-disable-line import/no-unassigned-import +import {onlyColors} from './fix-reporter-env.js'; + +onlyColors(); +import('../../lib/worker/base.js'); diff --git a/test-tap/helper/report.js b/test-tap/helper/report.js index 5ac88ff82..e3752cfdb 100644 --- a/test-tap/helper/report.js +++ b/test-tap/helper/report.js @@ -1,57 +1,20 @@ -'use strict'; -const childProcess = require('child_process'); -const workerThreads = require('worker_threads'); -const fs = require('fs'); -const path = require('path'); -const globby = require('globby'); -const proxyquire = require('proxyquire'); -const replaceString = require('replace-string'); -const pkg = require('../../package.json'); -const {normalizeGlobs} = require('../../lib/globs'); -const providerManager = require('../../lib/provider-manager'); - -const workerFile = path.join(__dirname, 'report-worker.js'); - -class Worker extends workerThreads.Worker { - constructor(filename, options) { - super(workerFile, { - ...options, - env: { - ...options.env, - NODE_NO_WARNINGS: '1' - } - }); - } -} - -let _Api = null; -const createApi = options => { - if (!_Api) { - _Api = proxyquire('../../lib/api', { - './fork': proxyquire('../../lib/fork', { - worker_threads: { // eslint-disable-line camelcase - ...workerThreads, - Worker - }, - child_process: { // eslint-disable-line camelcase - ...childProcess, - fork(filename, argv, options) { - return childProcess.fork(workerFile, argv, { - ...options, - env: { - ...options.env, - NODE_NO_WARNINGS: '1' - } - }); - } - } - }) - }); - } +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath, pathToFileURL} from 'url'; - options.workerThreads = false; - return new _Api(options); -}; +import globby from 'globby'; +import replaceString from 'replace-string'; + +import Api from '../../lib/api.js'; +import {_testOnlyReplaceWorkerPath} from '../../lib/fork.js'; +import {normalizeGlobs} from '../../lib/globs.js'; +import pkg from '../../lib/pkg.cjs'; +import providerManager from '../../lib/provider-manager.js'; + +_testOnlyReplaceWorkerPath(new URL('report-worker.js', import.meta.url)); + +const exports = {}; +export default exports; exports.assert = (t, logFile, buffer) => { let existing = null; @@ -76,24 +39,27 @@ exports.assert = (t, logFile, buffer) => { } }; +const cwdFileUrlPrefix = pathToFileURL(process.cwd()); + exports.sanitizers = { - cwd: string => replaceString(string, process.cwd(), '~'), + cwd: string => replaceString(replaceString(string, cwdFileUrlPrefix, ''), process.cwd(), '~'), experimentalWarning: string => string.replace(/^\(node:\d+\) ExperimentalWarning.+\n/g, ''), lineEndings: string => replaceString(string, '\r\n', '\n'), posix: string => replaceString(string, '\\', '/'), timers: string => string.replace(/timers\.js:\d+:\d+/g, 'timers.js'), - version: string => replaceString(string, `v${pkg.version}`, 'v1.0.0-beta.5.1') + version: string => replaceString(string, `v${pkg.version}`, 'VERSION') }; +const __dirname = fileURLToPath(new URL('.', import.meta.url)); exports.projectDir = type => path.join(__dirname, '../fixture/report', type.toLowerCase()); -const run = (type, reporter, {match = [], filter} = {}) => { +const run = async (type, reporter, {match = [], filter} = {}) => { const projectDir = exports.projectDir(type); const providers = [{ type: 'babel', level: 'ava-3', - main: providerManager.babel(projectDir).main({ + main: (await providerManager.babel(projectDir)).main({ config: { testOptions: { plugins: ['@babel/plugin-proposal-do-expressions'] @@ -103,7 +69,7 @@ const run = (type, reporter, {match = [], filter} = {}) => { }]; const options = { - extensions: ['js'], + extensions: ['cjs'], failFast: type === 'failFast' || type === 'failFast2', failWithoutAssertions: false, serial: type === 'failFast' || type === 'failFast2', @@ -117,15 +83,19 @@ const run = (type, reporter, {match = [], filter} = {}) => { concurrency: 1, updateSnapshots: false, snapshotDir: false, - chalkOptions: {level: 1} + chalkOptions: {level: 1}, + workerThreads: false, + env: { + NODE_NO_WARNINGS: '1' + } }; options.globs = normalizeGlobs({extensions: options.extensions, files: ['*'], providers: []}); - const api = createApi(options); + const api = new Api(options); api.on('run', plan => reporter.startRun(plan)); - const files = globby.sync('*.js', { + const files = globby.sync('*.cjs', { absolute: true, brace: true, case: false, @@ -170,7 +140,7 @@ exports.watch = reporter => run('watch', reporter); exports.edgeCases = reporter => run('edgeCases', reporter, { filter: [ {pattern: '**/*'}, - {pattern: '**/test.js', lineNumbers: [2]}, - {pattern: '**/ast-syntax-error.js', lineNumbers: [7]} + {pattern: '**/test.cjs', lineNumbers: [2]}, + {pattern: '**/ast-syntax-error.cjs', lineNumbers: [7]} ] }); diff --git a/test-tap/helper/tty-stream.js b/test-tap/helper/tty-stream.js index b27e6125d..50ed101d4 100644 --- a/test-tap/helper/tty-stream.js +++ b/test-tap/helper/tty-stream.js @@ -1,8 +1,8 @@ -'use strict'; -const stream = require('stream'); -const ansiEscapes = require('ansi-escapes'); +import stream from 'stream'; -class TTYStream extends stream.Writable { +import ansiEscapes from 'ansi-escapes'; + +export default class TTYStream extends stream.Writable { constructor(options) { super(); @@ -65,5 +65,3 @@ class TTYStream extends stream.Writable { } TTYStream.SEPARATOR = Buffer.from('---tty-stream-chunk-separator\n', 'utf8'); - -module.exports = TTYStream; diff --git a/test-tap/hooks.js b/test-tap/hooks.js index 4b40f16a6..4cb107186 100644 --- a/test-tap/hooks.js +++ b/test-tap/hooks.js @@ -1,9 +1,9 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({}); +import {test} from 'tap'; -const {test} = require('tap'); -const Runner = require('../lib/runner'); +import Runner from '../lib/runner.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +setOptions({}); const promiseEnd = (runner, next) => { return new Promise(resolve => { diff --git a/test-tap/integration/assorted.js b/test-tap/integration/assorted.js index 074724d84..d2638c2fb 100644 --- a/test-tap/integration/assorted.js +++ b/test-tap/integration/assorted.js @@ -1,13 +1,17 @@ -'use strict'; -const fs = require('fs'); -const childProcess = require('child_process'); -const path = require('path'); -const stripAnsi = require('strip-ansi'); -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import childProcess from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; + +import stripAnsi from 'strip-ansi'; +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); test('timeout', t => { - execCli(['long-running.js', '-T', '1s'], (err, stdout) => { + execCli(['long-running.cjs', '-T', '1s'], (err, stdout) => { t.ok(err); t.match(stdout, /Timed out/); t.end(); @@ -16,7 +20,7 @@ test('timeout', t => { // FIXME: This test fails in CI, but not locally. Re-enable at some point… // test('interrupt', t => { -// const proc = execCli(['long-running.js'], (_, stdout) => { +// const proc = execCli(['long-running.cjs'], (_, stdout) => { // t.match(stdout, /SIGINT/); // t.end(); // }); @@ -27,15 +31,15 @@ test('timeout', t => { // }); test('include anonymous functions in error reports', t => { - execCli('error-in-anonymous-function.js', (err, stdout) => { + execCli('error-in-anonymous-function.cjs', (err, stdout) => { t.ok(err); - t.match(stdout, /error-in-anonymous-function\.js:4:8/); + t.match(stdout, /error-in-anonymous-function\.cjs:4:8/); t.end(); }); }); test('--match works', t => { - execCli(['-m=foo', '-m=bar', '-m=!baz', '-m=t* a* f*', '-m=!t* a* n* f*', 'matcher-skip.js'], err => { + execCli(['-m=foo', '-m=bar', '-m=!baz', '-m=t* a* f*', '-m=!t* a* n* f*', 'matcher-skip.cjs'], err => { t.error(err); t.end(); }); @@ -43,7 +47,7 @@ test('--match works', t => { for (const tapFlag of ['--tap', '-t']) { test(`${tapFlag} should produce TAP output`, t => { - execCli([tapFlag, 'test.js'], {dirname: 'fixture/watcher'}, err => { + execCli([tapFlag, 'test.cjs'], {dirname: 'fixture/watcher'}, err => { t.ok(!err); t.end(); }); @@ -74,7 +78,7 @@ test('tests without assertions do not fail if failWithoutAssertions option is se }); test('--no-color disables formatting colors', t => { - execCli(['--no-color', '--verbose', 'formatting-color.js'], (err, stdout) => { + execCli(['--no-color', '--verbose', 'formatting-color.cjs'], (err, stdout) => { t.ok(err); t.equal(stripAnsi(stdout), stdout); t.end(); @@ -82,7 +86,7 @@ test('--no-color disables formatting colors', t => { }); test('--color enables formatting colors', t => { - execCli(['--color', '--verbose', 'formatting-color.js'], (err, stdout) => { + execCli(['--color', '--verbose', 'formatting-color.cjs'], (err, stdout) => { t.ok(err); t.not(stripAnsi(stdout), stdout); t.end(); @@ -90,7 +94,7 @@ test('--color enables formatting colors', t => { }); test('sets NODE_ENV to test when it is not set', t => { - execCli('node-env-test.js', {env: {}}, (err, stdout) => { + execCli('node-env-test.cjs', {env: {}}, (err, stdout) => { t.error(err); t.match(stdout, /1 test passed/); t.end(); @@ -98,7 +102,7 @@ test('sets NODE_ENV to test when it is not set', t => { }); test('doesn’t set NODE_ENV when it is set', t => { - execCli('node-env-foo.js', {env: {NODE_ENV: 'foo'}}, (err, stdout) => { + execCli('node-env-foo.cjs', {env: {NODE_ENV: 'foo'}}, (err, stdout) => { t.error(err); t.match(stdout, /1 test passed/); t.end(); @@ -106,7 +110,7 @@ test('doesn’t set NODE_ENV when it is set', t => { }); test('additional arguments are forwarded to the worker', t => { - execCli(['worker-argv.js', '--serial', '--', '--hello', 'world'], err => { + execCli(['worker-argv.cjs', '--serial', '--', '--hello', 'world'], err => { t.error(err); t.end(); }); diff --git a/test-tap/integration/debug.js b/test-tap/integration/debug.js index da27789a8..ad451a4ae 100644 --- a/test-tap/integration/debug.js +++ b/test-tap/integration/debug.js @@ -1,9 +1,9 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; test('bails when using --watch while while debugging', t => { - execCli(['debug', '--watch', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { + execCli(['debug', '--watch', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { t.equal(err.code, 1); t.match(stderr, 'Watch mode is not available when debugging.'); t.end(); @@ -11,7 +11,7 @@ test('bails when using --watch while while debugging', t => { }); test('bails when debugging in CI', t => { - execCli(['debug', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'ci'}}, (err, stdout, stderr) => { + execCli(['debug', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'ci'}}, (err, stdout, stderr) => { t.equal(err.code, 1); t.match(stderr, 'Debugging is not available in CI.'); t.end(); @@ -19,7 +19,7 @@ test('bails when debugging in CI', t => { }); test('bails when --tap reporter is used while debugging', t => { - execCli(['debug', '--tap', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { + execCli(['debug', '--tap', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { t.equal(err.code, 1); t.match(stderr, 'The TAP reporter is not available when debugging.'); t.end(); diff --git a/test-tap/integration/parallel-runs.js b/test-tap/integration/parallel-runs.js index 4de806e9b..305ca5b83 100644 --- a/test-tap/integration/parallel-runs.js +++ b/test-tap/integration/parallel-runs.js @@ -1,6 +1,6 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; test('correctly distributes more test files than CI_NODE_TOTAL', t => { t.plan(3); diff --git a/test-tap/integration/repl.js b/test-tap/integration/repl.js index e34b631db..6ecfb4e72 100644 --- a/test-tap/integration/repl.js +++ b/test-tap/integration/repl.js @@ -1,6 +1,5 @@ -'use strict'; -const {test} = require('tap'); -const execa = require('execa'); +import execa from 'execa'; +import {test} from 'tap'; test('Throws error when required from the REPL', t => { return execa('node', ['-r', 'ava'], {reject: false}).then(result => { diff --git a/test-tap/integration/snapshots.js b/test-tap/integration/snapshots.js index e68857caa..1ad19bbdc 100644 --- a/test-tap/integration/snapshots.js +++ b/test-tap/integration/snapshots.js @@ -1,10 +1,14 @@ -'use strict'; -const fs = require('fs'); -const path = require('path'); -const execa = require('execa'); -const {test} = require('tap'); -const tempy = require('tempy'); -const {execCli} = require('../helper/cli'); +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; + +import execa from 'execa'; +import {test} from 'tap'; +import tempy from 'tempy'; + +import {execCli} from '../helper/cli.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); for (const object of [ {type: 'colocated', rel: '', dir: ''}, @@ -13,7 +17,7 @@ for (const object of [ {type: 'tests', rel: 'tests-dir', dir: 'tests/snapshots'} ]) { test(`snapshots work (${object.type})`, t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', object.rel, object.dir, 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', object.rel, object.dir, 'test.cjs.snap'); try { fs.unlinkSync(snapPath); } catch (error) { @@ -38,8 +42,8 @@ for (const object of [ } test('appends to existing snapshots', t => { - const cliPath = require.resolve('../../entrypoints/cli.mjs'); - const avaPath = require.resolve('../../entrypoints/main.cjs'); + const cliPath = fileURLToPath(new URL('../../entrypoints/cli.mjs', import.meta.url)); + const avaPath = fileURLToPath(new URL('../../entrypoints/main.cjs', import.meta.url)); const cwd = tempy.directory(); fs.writeFileSync(path.join(cwd, 'package.json'), '{}'); @@ -48,13 +52,13 @@ test('appends to existing snapshots', t => { test('one', t => { t.snapshot({one: true}) })`; - fs.writeFileSync(path.join(cwd, 'test.js'), initial); + fs.writeFileSync(path.join(cwd, 'test.cjs'), initial); const run = () => execa(process.execPath, [cliPath, '--verbose', '--no-color'], {cwd, env: {AVA_FORCE_CI: 'not-ci'}, reject: false}); return run().then(result => { t.match(result.stdout, /1 test passed/); - fs.writeFileSync(path.join(cwd, 'test.js'), `${initial} + fs.writeFileSync(path.join(cwd, 'test.cjs'), `${initial} test('two', t => { t.snapshot({two: true}) })`); @@ -62,7 +66,7 @@ test('two', t => { }).then(result => { t.match(result.stdout, /2 tests passed/); - fs.writeFileSync(path.join(cwd, 'test.js'), `${initial} + fs.writeFileSync(path.join(cwd, 'test.cjs'), `${initial} test('two', t => { t.snapshot({two: false}) })`); @@ -74,10 +78,10 @@ test('two', t => { }); test('outdated snapshot version is reported to the console', t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap'); fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x00, 0x00])); - execCli(['test.js'], {dirname: 'fixture/snapshots'}, (error, stdout) => { + execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => { t.ok(error); t.match(stdout, /The snapshot file is v0, but only v3 is supported\./); t.match(stdout, /File path:/); @@ -88,10 +92,10 @@ test('outdated snapshot version is reported to the console', t => { }); test('outdated snapshot version can be updated', t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap'); fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x00, 0x00])); - execCli(['test.js', '--update-snapshots'], {dirname: 'fixture/snapshots', env: {AVA_FORCE_CI: 'not-ci'}}, (error, stdout) => { + execCli(['test.cjs', '--update-snapshots'], {dirname: 'fixture/snapshots', env: {AVA_FORCE_CI: 'not-ci'}}, (error, stdout) => { t.error(error); t.match(stdout, /2 tests passed/); t.end(); @@ -99,10 +103,10 @@ test('outdated snapshot version can be updated', t => { }); test('newer snapshot version is reported to the console', t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap'); fs.writeFileSync(snapPath, Buffer.from([0x0A, 0xFF, 0xFF])); - execCli(['test.js'], {dirname: 'fixture/snapshots'}, (error, stdout) => { + execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => { t.ok(error); t.match(stdout, /The snapshot file is v65535, but only v3 is supported\./); t.match(stdout, /File path:/); @@ -113,10 +117,10 @@ test('newer snapshot version is reported to the console', t => { }); test('snapshot corruption is reported to the console', t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap'); fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x03, 0x00])); - execCli(['test.js'], {dirname: 'fixture/snapshots'}, (error, stdout) => { + execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => { t.ok(error); t.match(stdout, /The snapshot file is corrupted\./); t.match(stdout, /File path:/); @@ -127,10 +131,10 @@ test('snapshot corruption is reported to the console', t => { }); test('legacy snapshot files are reported to the console', t => { - const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.js.snap'); + const snapPath = path.join(__dirname, '..', 'fixture', 'snapshots', 'test.cjs.snap'); fs.writeFileSync(snapPath, Buffer.from('// Jest Snapshot v1, https://goo.gl/fbAQLP\n')); - execCli(['test.js'], {dirname: 'fixture/snapshots'}, (error, stdout) => { + execCli(['test.cjs'], {dirname: 'fixture/snapshots'}, (error, stdout) => { t.ok(error); t.match(stdout, /The snapshot file was created with AVA 0\.19\. It’s not supported by this AVA version\./); t.match(stdout, /File path:/); @@ -199,8 +203,8 @@ test('snapshots resolved location from "snapshotDir" in AVA config', t => { .map(snapRelativeDir => { const snapPath = path.join(__dirname, '..', relativeFixtureDir, snapDir, snapRelativeDir); return [ - path.join(snapPath, 'test.js.md'), - path.join(snapPath, 'test.js.snap') + path.join(snapPath, 'test.cjs.md'), + path.join(snapPath, 'test.cjs.snap') ]; }) .reduce((a, b) => [...a, ...b], []); @@ -233,12 +237,12 @@ test('snapshots resolved location from "snapshotDir" in AVA config', t => { }); }); -test('snapshots are indentical on different platforms', t => { +test('snapshots are identical on different platforms', t => { const fixtureDir = path.join(__dirname, '..', 'fixture', 'snapshots', 'test-content'); - const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.md'); - const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.snap'); - const expectedReportPath = path.join(fixtureDir, 'test.js.md.expected'); - const expectedSnapPath = path.join(fixtureDir, 'test.js.snap.expected'); + const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.md'); + const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.snap'); + const expectedReportPath = path.join(fixtureDir, 'test.cjs.md.expected'); + const expectedSnapPath = path.join(fixtureDir, 'test.cjs.snap.expected'); const removeFile = filePath => { try { @@ -274,8 +278,8 @@ test('snapshots are indentical on different platforms', t => { test('in CI, new snapshots are not recorded', t => { const fixtureDir = path.join(__dirname, '..', 'fixture', 'snapshots', 'test-content'); - const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.md'); - const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.js.snap'); + const reportPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.md'); + const snapPath = path.join(fixtureDir, 'tests', 'snapshots', 'test.cjs.snap'); const removeFile = filePath => { try { diff --git a/test-tap/integration/stack-traces.js b/test-tap/integration/stack-traces.js index 1c3997bc4..1ed331392 100644 --- a/test-tap/integration/stack-traces.js +++ b/test-tap/integration/stack-traces.js @@ -1,14 +1,14 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; test('`AssertionError` should capture infinity stack trace', t => { - execCli('infinity-stack-trace.js', (err, stdout) => { + execCli('infinity-stack-trace.cjs', (err, stdout) => { t.ok(err); - t.match(stdout, /c \(.*infinity-stack-trace\.js:6:20\)/); - t.match(stdout, /b \(.*infinity-stack-trace\.js:7:18\)/); - t.match(stdout, /a \(.*infinity-stack-trace\.js:8:18\)/); - t.match(stdout, /.+?infinity-stack-trace\.js:10:2/); + t.match(stdout, /c \(.*infinity-stack-trace\.cjs:6:20\)/); + t.match(stdout, /b \(.*infinity-stack-trace\.cjs:7:18\)/); + t.match(stdout, /a \(.*infinity-stack-trace\.cjs:8:18\)/); + t.match(stdout, /.+?infinity-stack-trace\.cjs:10:2/); t.end(); }); }); diff --git a/test-tap/integration/stalled.js b/test-tap/integration/stalled.js index 625c3c763..92aab92f9 100644 --- a/test-tap/integration/stalled.js +++ b/test-tap/integration/stalled.js @@ -1,16 +1,16 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; test('observable tests fail if event loop empties before they’re resolved', t => { - execCli('observable.js', {dirname: 'fixture/stalled-tests'}, (_, stdout) => { + execCli('observable.cjs', {dirname: 'fixture/stalled-tests'}, (_, stdout) => { t.match(stdout, /Observable returned by test never completed/); t.end(); }); }); test('promise tests fail if event loop empties before they’re resolved', t => { - execCli('promise.js', {dirname: 'fixture/stalled-tests'}, (_, stdout) => { + execCli('promise.cjs', {dirname: 'fixture/stalled-tests'}, (_, stdout) => { t.match(stdout, /Promise returned by test never resolved/); t.end(); }); diff --git a/test-tap/integration/t-throws.js b/test-tap/integration/t-throws.js index 94b780306..44757e067 100644 --- a/test-tap/integration/t-throws.js +++ b/test-tap/integration/t-throws.js @@ -1,9 +1,9 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); +import {test} from 'tap'; + +import {execCli} from '../helper/cli.js'; test('improper use of t.throws will be reported to the console', t => { - execCli('throws.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('throws.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -13,7 +13,7 @@ test('improper use of t.throws will be reported to the console', t => { }); test('improper use of t.throws from within a Promise will be reported to the console', t => { - execCli('promise.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('promise.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -23,7 +23,7 @@ test('improper use of t.throws from within a Promise will be reported to the con }); test('improper use of t.throws from within a pending promise, even if caught and rethrown immediately, will be reported to the console', t => { - execCli('leaked-from-promise.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('leaked-from-promise.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -33,7 +33,7 @@ test('improper use of t.throws from within a pending promise, even if caught and }); test('improper use of t.throws, swallowed as an unhandled rejection, will be reported to the console', t => { - execCli('unhandled-rejection.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('unhandled-rejection.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -43,7 +43,7 @@ test('improper use of t.throws, swallowed as an unhandled rejection, will be rep }); test('improper use of t.throws, even if caught, will be reported to the console', t => { - execCli('caught.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('caught.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.notMatch(stdout, /should be detected/); @@ -53,7 +53,7 @@ test('improper use of t.throws, even if caught, will be reported to the console' }); test('improper use of t.throws, even if caught and then rethrown immediately, will be reported to the console', t => { - execCli('caught-and-leaked.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('caught-and-leaked.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -63,7 +63,7 @@ test('improper use of t.throws, even if caught and then rethrown immediately, wi }); test('improper use of t.throws, even if caught and then later rethrown, will be reported to the console', t => { - execCli('caught-and-leaked-slowly.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('caught-and-leaked-slowly.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.match(stdout, /should be detected/); @@ -73,7 +73,7 @@ test('improper use of t.throws, even if caught and then later rethrown, will be }); test('improper use of t.throws, even if caught and then rethrown too slowly, will be reported to the console', t => { - execCli('caught-and-leaked-too-slowly.js', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { + execCli('caught-and-leaked-too-slowly.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => { t.ok(err); t.match(stdout, /Improper usage of `t\.throws\(\)` detected/); t.notMatch(stdout, /should be detected/); diff --git a/test-tap/integration/watcher.js b/test-tap/integration/watcher.js index ab3211f4e..cbd414056 100644 --- a/test-tap/integration/watcher.js +++ b/test-tap/integration/watcher.js @@ -1,15 +1,19 @@ -'use strict'; -const path = require('path'); -const {test} = require('tap'); -const touch = require('touch'); -const {execCli} = require('../helper/cli'); +import path from 'path'; +import {fileURLToPath} from 'url'; + +import {test} from 'tap'; +import touch from 'touch'; + +import {execCli} from '../helper/cli.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); const END_MESSAGE = 'Type `r` and press enter to rerun tests\nType `u` and press enter to update snapshots\n'; test('watcher reruns test files upon change', t => { let killed = false; - const child = execCli(['--verbose', '--watch', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, err => { + const child = execCli(['--verbose', '--watch', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, err => { t.ok(killed); t.error(err); t.end(); @@ -21,7 +25,7 @@ test('watcher reruns test files upon change', t => { buffer += string; if (buffer.includes('1 test passed')) { if (!passedFirst) { - touch.sync(path.join(__dirname, '../fixture/watcher/test.js')); + touch.sync(path.join(__dirname, '../fixture/watcher/test.cjs')); buffer = ''; passedFirst = true; } else if (!killed) { @@ -35,7 +39,7 @@ test('watcher reruns test files upon change', t => { test('watcher reruns test files when source dependencies change', t => { let killed = false; - const child = execCli(['--verbose', '--watch', 'test-1.js', 'test-2.js'], {dirname: 'fixture/watcher/with-dependencies', env: {AVA_FORCE_CI: 'not-ci'}}, err => { + const child = execCli(['--verbose', '--watch', 'test-1.cjs', 'test-2.cjs'], {dirname: 'fixture/watcher/with-dependencies', env: {AVA_FORCE_CI: 'not-ci'}}, err => { t.ok(killed); t.error(err); t.end(); @@ -46,7 +50,7 @@ test('watcher reruns test files when source dependencies change', t => { child.stdout.on('data', string => { buffer += string; if (buffer.includes('2 tests passed') && !passedFirst) { - touch.sync(path.join(__dirname, '../fixture/watcher/with-dependencies/source.js')); + touch.sync(path.join(__dirname, '../fixture/watcher/with-dependencies/source.cjs')); buffer = ''; passedFirst = true; } else if (buffer.includes('1 test passed') && !killed) { @@ -59,7 +63,7 @@ test('watcher reruns test files when source dependencies change', t => { test('watcher does not rerun test files when they write snapshot files', t => { let killed = false; - const child = execCli(['--verbose', '--watch', '--update-snapshots', 'test.js'], {dirname: 'fixture/snapshots/watcher-rerun', env: {AVA_FORCE_CI: 'not-ci'}}, err => { + const child = execCli(['--verbose', '--watch', '--update-snapshots', 'test.cjs'], {dirname: 'fixture/snapshots/watcher-rerun', env: {AVA_FORCE_CI: 'not-ci'}}, err => { t.ok(killed); t.error(err); t.end(); @@ -97,7 +101,7 @@ test('watcher does not rerun test files when they unlink snapshot files', t => { let killed = false; const child = execCli( - ['--verbose', '--watch', '--update-snapshots', 'test.js'], + ['--verbose', '--watch', '--update-snapshots', 'test.cjs'], { dirname: 'fixture/snapshots/watcher-rerun-unlink', env: {AVA_FORCE_CI: 'not-ci'} @@ -142,7 +146,7 @@ test('watcher does not rerun test files when ignored files change', t => { child.stdout.on('data', string => { buffer += string; if (buffer.includes('1 test passed') && !passedFirst) { - touch.sync(path.join(__dirname, '../fixture/watcher/ignored-files/ignored.js')); + touch.sync(path.join(__dirname, '../fixture/watcher/ignored-files/ignored.cjs')); buffer = ''; passedFirst = true; setTimeout(() => { @@ -158,7 +162,7 @@ test('watcher does not rerun test files when ignored files change', t => { test('watcher reruns test files when snapshot dependencies change', t => { let killed = false; - const child = execCli(['--verbose', '--watch', '--update-snapshots', 'test.js'], {dirname: 'fixture/snapshots/watcher-rerun', env: {AVA_FORCE_CI: 'not-ci'}}, err => { + const child = execCli(['--verbose', '--watch', '--update-snapshots', 'test.cjs'], {dirname: 'fixture/snapshots/watcher-rerun', env: {AVA_FORCE_CI: 'not-ci'}}, err => { t.ok(killed); t.error(err); t.end(); @@ -186,7 +190,7 @@ test('watcher reruns test files when snapshot dependencies change', t => { test('`"tap": true` config is ignored when --watch is given', t => { let killed = false; - const child = execCli(['--watch', '--verbose', 'test.js'], {dirname: 'fixture/watcher/tap-in-conf', env: {AVA_FORCE_CI: 'not-ci'}}, () => { + const child = execCli(['--watch', '--verbose', 'test.cjs'], {dirname: 'fixture/watcher/tap-in-conf', env: {AVA_FORCE_CI: 'not-ci'}}, () => { t.ok(killed); t.end(); }); @@ -206,7 +210,7 @@ test('`"tap": true` config is ignored when --watch is given', t => { }); test('bails when --tap reporter is used while --watch is given', t => { - execCli(['--tap', '--watch', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { + execCli(['--tap', '--watch', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'not-ci'}}, (err, stdout, stderr) => { t.equal(err.code, 1); t.match(stderr, 'The TAP reporter is not available when using watch mode.'); t.end(); @@ -214,7 +218,7 @@ test('bails when --tap reporter is used while --watch is given', t => { }); test('bails when CI is used while --watch is given', t => { - execCli(['--watch', 'test.js'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'ci'}}, (err, stdout, stderr) => { + execCli(['--watch', 'test.cjs'], {dirname: 'fixture/watcher', env: {AVA_FORCE_CI: 'ci'}}, (err, stdout, stderr) => { t.equal(err.code, 1); t.match(stderr, 'Watch mode is not available in CI, as it prevents AVA from terminating.'); t.end(); diff --git a/test-tap/line-numbers.js b/test-tap/line-numbers.js index 41eb58c3d..93bf0d64a 100644 --- a/test-tap/line-numbers.js +++ b/test-tap/line-numbers.js @@ -1,10 +1,6 @@ -'use strict'; +import {test} from 'tap'; -const {test} = require('tap'); -const { - splitPatternAndLineNumbers, - getApplicableLineNumbers -} = require('../lib/line-numbers'); +import {splitPatternAndLineNumbers, getApplicableLineNumbers} from '../lib/line-numbers.js'; test('no line numbers', t => { t.strictSame(splitPatternAndLineNumbers('test.js'), {pattern: 'test.js', lineNumbers: null}); diff --git a/test-tap/node-arguments.js b/test-tap/node-arguments.js index 718030a74..2c39d15b8 100644 --- a/test-tap/node-arguments.js +++ b/test-tap/node-arguments.js @@ -1,12 +1,11 @@ -'use strict'; +import {test} from 'tap'; -const {test} = require('tap'); -const normalizeNodeArguments = require('../lib/node-arguments'); +import normalizeNodeArguments from '../lib/node-arguments.js'; test('combines arguments', async t => { t.same( - await normalizeNodeArguments(['--require setup.js'], '--throw-deprecation --zero-fill-buffers'), - [...process.execArgv, '--require setup.js', '--throw-deprecation', '--zero-fill-buffers'] + await normalizeNodeArguments(['--require setup.cjs'], '--throw-deprecation --zero-fill-buffers'), + [...process.execArgv, '--require setup.cjs', '--throw-deprecation', '--zero-fill-buffers'] ); t.end(); }); diff --git a/test-tap/promise.js b/test-tap/promise.js index dea3a5e83..e5561db16 100644 --- a/test-tap/promise.js +++ b/test-tap/promise.js @@ -1,9 +1,10 @@ -'use strict'; -require('../lib/chalk').set({level: 0}); -require('../lib/worker/options').set({}); +import {test} from 'tap'; -const {test} = require('tap'); -const Test = require('../lib/test'); +import './helper/chalk0.js'; // eslint-disable-line import/no-unassigned-import +import Test from '../lib/test.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +setOptions({}); function ava(fn) { return new Test({ diff --git a/test-tap/reporters/improper-usage-messages.js b/test-tap/reporters/improper-usage-messages.js index c9aa14578..a38783796 100644 --- a/test-tap/reporters/improper-usage-messages.js +++ b/test-tap/reporters/improper-usage-messages.js @@ -1,8 +1,6 @@ -'use strict'; -require('../../lib/chalk').set(); +import {test} from 'tap'; -const {test} = require('tap'); -const improperUsageMessages = require('../../lib/reporters/improper-usage-messages'); +import improperUsageMessages from '../../lib/reporters/improper-usage-messages.js'; test('results when nothing is applicable', t => { const err = { @@ -15,7 +13,7 @@ test('results when nothing is applicable', t => { } }; - const actualOutput = improperUsageMessages.forError(err); + const actualOutput = improperUsageMessages(err); t.equal(actualOutput, null); t.end(); diff --git a/test-tap/reporters/mini.edgecases.v12.log b/test-tap/reporters/mini.edgecases.v12.log index e3e8c408d..ef8cc8ee9 100644 --- a/test-tap/reporters/mini.edgecases.v12.log +++ b/test-tap/reporters/mini.edgecases.v12.log @@ -3,29 +3,29 @@ ---tty-stream-chunk-separator * ---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ⚠ Could not parse ast-syntax-error.js for line number selection---tty-stream-chunk-separator +* ⚠ Could not parse ast-syntax-error.cjs for line number selection---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for ast-syntax-error.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for ast-syntax-error.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in ava-import-no-test-declaration.js---tty-stream-chunk-separator +* ✖ No tests found in ava-import-no-test-declaration.cjs---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator +* ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for test.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for test.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file - ✖ No tests found in ava-import-no-test-declaration.js - ✖ No tests found in import-and-use-test-member.js - ✖ No tests found in throws.js - ⚠ Could not parse ast-syntax-error.js for line number selection - ✖ Line numbers for ast-syntax-error.js did not match any tests - ✖ Line numbers for test.js did not match any tests +[?25h ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file + ✖ No tests found in ava-import-no-test-declaration.cjs + ✖ No tests found in import-and-use-test-member.cjs + ✖ No tests found in throws.cjs + ⚠ Could not parse ast-syntax-error.cjs for line number selection + ✖ Line numbers for ast-syntax-error.cjs did not match any tests + ✖ Line numbers for test.cjs did not match any tests ─ - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -33,20 +33,20 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ─ diff --git a/test-tap/reporters/mini.edgecases.v14.log b/test-tap/reporters/mini.edgecases.v14.log index e3e8c408d..ef8cc8ee9 100644 --- a/test-tap/reporters/mini.edgecases.v14.log +++ b/test-tap/reporters/mini.edgecases.v14.log @@ -3,29 +3,29 @@ ---tty-stream-chunk-separator * ---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ⚠ Could not parse ast-syntax-error.js for line number selection---tty-stream-chunk-separator +* ⚠ Could not parse ast-syntax-error.cjs for line number selection---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for ast-syntax-error.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for ast-syntax-error.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in ava-import-no-test-declaration.js---tty-stream-chunk-separator +* ✖ No tests found in ava-import-no-test-declaration.cjs---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator +* ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for test.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for test.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file - ✖ No tests found in ava-import-no-test-declaration.js - ✖ No tests found in import-and-use-test-member.js - ✖ No tests found in throws.js - ⚠ Could not parse ast-syntax-error.js for line number selection - ✖ Line numbers for ast-syntax-error.js did not match any tests - ✖ Line numbers for test.js did not match any tests +[?25h ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file + ✖ No tests found in ava-import-no-test-declaration.cjs + ✖ No tests found in import-and-use-test-member.cjs + ✖ No tests found in throws.cjs + ⚠ Could not parse ast-syntax-error.cjs for line number selection + ✖ Line numbers for ast-syntax-error.cjs did not match any tests + ✖ Line numbers for test.cjs did not match any tests ─ - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -33,20 +33,20 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ─ diff --git a/test-tap/reporters/mini.edgecases.v16.log b/test-tap/reporters/mini.edgecases.v16.log index e3e8c408d..ef8cc8ee9 100644 --- a/test-tap/reporters/mini.edgecases.v16.log +++ b/test-tap/reporters/mini.edgecases.v16.log @@ -3,29 +3,29 @@ ---tty-stream-chunk-separator * ---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ⚠ Could not parse ast-syntax-error.js for line number selection---tty-stream-chunk-separator +* ⚠ Could not parse ast-syntax-error.cjs for line number selection---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for ast-syntax-error.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for ast-syntax-error.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in ava-import-no-test-declaration.js---tty-stream-chunk-separator +* ✖ No tests found in ava-import-no-test-declaration.cjs---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator +* ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file---tty-stream-chunk-separator ---tty-stream-chunk-separator -* ✖ Line numbers for test.js did not match any tests---tty-stream-chunk-separator +* ✖ Line numbers for test.cjs did not match any tests---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file - ✖ No tests found in ava-import-no-test-declaration.js - ✖ No tests found in import-and-use-test-member.js - ✖ No tests found in throws.js - ⚠ Could not parse ast-syntax-error.js for line number selection - ✖ Line numbers for ast-syntax-error.js did not match any tests - ✖ Line numbers for test.js did not match any tests +[?25h ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file + ✖ No tests found in ava-import-no-test-declaration.cjs + ✖ No tests found in import-and-use-test-member.cjs + ✖ No tests found in throws.cjs + ⚠ Could not parse ast-syntax-error.cjs for line number selection + ✖ Line numbers for ast-syntax-error.cjs did not match any tests + ✖ Line numbers for test.cjs did not match any tests ─ - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -33,20 +33,20 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ─ diff --git a/test-tap/reporters/mini.failfast.v12.log b/test-tap/reporters/mini.failfast.v12.log index 6aa34aec6..deabc82b8 100644 --- a/test-tap/reporters/mini.failfast.v12.log +++ b/test-tap/reporters/mini.failfast.v12.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.failfast.v14.log b/test-tap/reporters/mini.failfast.v14.log index 6aa34aec6..deabc82b8 100644 --- a/test-tap/reporters/mini.failfast.v14.log +++ b/test-tap/reporters/mini.failfast.v14.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.failfast.v16.log b/test-tap/reporters/mini.failfast.v16.log index 6aa34aec6..deabc82b8 100644 --- a/test-tap/reporters/mini.failfast.v16.log +++ b/test-tap/reporters/mini.failfast.v16.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.failfast2.v12.log b/test-tap/reporters/mini.failfast2.v12.log index 6f96c428e..15a4e35f9 100644 --- a/test-tap/reporters/mini.failfast2.v12.log +++ b/test-tap/reporters/mini.failfast2.v12.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.failfast2.v14.log b/test-tap/reporters/mini.failfast2.v14.log index 6f96c428e..15a4e35f9 100644 --- a/test-tap/reporters/mini.failfast2.v14.log +++ b/test-tap/reporters/mini.failfast2.v14.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.failfast2.v16.log b/test-tap/reporters/mini.failfast2.v16.log index 6f96c428e..15a4e35f9 100644 --- a/test-tap/reporters/mini.failfast2.v16.log +++ b/test-tap/reporters/mini.failfast2.v16.log @@ -9,7 +9,7 @@ ---tty-stream-chunk-separator [?25h a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -17,7 +17,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/mini.js b/test-tap/reporters/mini.js index effe5a922..77529a572 100644 --- a/test-tap/reporters/mini.js +++ b/test-tap/reporters/mini.js @@ -1,45 +1,51 @@ -'use strict'; -require('../helper/fix-reporter-env')(); - -const path = require('path'); -const {test} = require('tap'); -const TTYStream = require('../helper/tty-stream'); -const report = require('../helper/report'); -const Reporter = require('../../lib/reporters/default'); - -const run = (type, sanitizers = []) => t => { - t.plan(1); - - const logFile = path.join(__dirname, `mini.${type.toLowerCase()}.${process.version.split('.')[0]}.log`); - - const tty = new TTYStream({ - columns: 200, - sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers, report.sanitizers.version] - }); - const reporter = new Reporter({ - projectDir: report.projectDir(type), - spinner: { - interval: 60 * 60 * 1000, // No need to update the spinner - color: false, - frames: ['*'] - }, - reportStream: tty, - stdStream: tty, - watching: type === 'watch' - }); - - return report[type](reporter) - .then(() => { - tty.end(); - return tty.asBuffer(); - }) - .then(buffer => report.assert(t, logFile, buffer)) - .catch(t.threw); -}; - -test('mini reporter - regular run', run('regular')); -test('mini reporter - failFast run', run('failFast')); -test('mini reporter - second failFast run', run('failFast2')); -test('mini reporter - only run', run('only')); -test('mini reporter - watch mode run', run('watch')); -test('mini reporter - edge cases', run('edgeCases')); +import {fileURLToPath} from 'url'; + +import {test} from 'tap'; + +import fixReporterEnv from '../helper/fix-reporter-env.js'; +import report from '../helper/report.js'; +import TTYStream from '../helper/tty-stream.js'; + +fixReporterEnv(); + +test(async t => { + const {default: Reporter} = await import('../../lib/reporters/default.js'); + + const run = (type, sanitizers = []) => t => { + t.plan(1); + + const logFile = fileURLToPath(new URL(`mini.${type.toLowerCase()}.${process.version.split('.')[0]}.log`, import.meta.url)); + + const tty = new TTYStream({ + columns: 200, + sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers, report.sanitizers.version] + }); + const reporter = new Reporter({ + extensions: ['cjs'], + projectDir: report.projectDir(type), + spinner: { + interval: 60 * 60 * 1000, // No need to update the spinner + color: false, + frames: ['*'] + }, + reportStream: tty, + stdStream: tty, + watching: type === 'watch' + }); + + return report[type](reporter) + .then(() => { + tty.end(); + return tty.asBuffer(); + }) + .then(buffer => report.assert(t, logFile, buffer)) + .catch(t.threw); + }; + + t.test('mini reporter - regular run', run('regular')); + t.test('mini reporter - failFast run', run('failFast')); + t.test('mini reporter - second failFast run', run('failFast2')); + t.test('mini reporter - only run', run('only')); + t.test('mini reporter - watch mode run', run('watch')); + t.test('mini reporter - edge cases', run('edgeCases')); +}); diff --git a/test-tap/reporters/mini.regular.v12.log b/test-tap/reporters/mini.regular.v12.log index 985df31c0..ab42c72f6 100644 --- a/test-tap/reporters/mini.regular.v12.log +++ b/test-tap/reporters/mini.regular.v12.log @@ -163,17 +163,17 @@ 1 skipped 1 todo---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in bad-test-chain.js +[?25h ✖ No tests found in bad-test-chain.cjs ─ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -192,17 +192,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -215,13 +215,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -229,13 +229,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -243,7 +243,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -258,7 +258,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -266,13 +266,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -283,13 +283,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -302,13 +302,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -328,16 +328,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -357,10 +357,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -374,7 +374,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -390,15 +390,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -410,15 +410,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -430,15 +430,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -450,15 +450,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -474,14 +474,14 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -489,13 +489,13 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -503,13 +503,13 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -517,11 +517,11 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null diff --git a/test-tap/reporters/mini.regular.v14.log b/test-tap/reporters/mini.regular.v14.log index 985df31c0..ab42c72f6 100644 --- a/test-tap/reporters/mini.regular.v14.log +++ b/test-tap/reporters/mini.regular.v14.log @@ -163,17 +163,17 @@ 1 skipped 1 todo---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in bad-test-chain.js +[?25h ✖ No tests found in bad-test-chain.cjs ─ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -192,17 +192,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -215,13 +215,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -229,13 +229,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -243,7 +243,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -258,7 +258,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -266,13 +266,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -283,13 +283,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -302,13 +302,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -328,16 +328,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -357,10 +357,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -374,7 +374,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -390,15 +390,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -410,15 +410,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -430,15 +430,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -450,15 +450,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -474,14 +474,14 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -489,13 +489,13 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -503,13 +503,13 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -517,11 +517,11 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null diff --git a/test-tap/reporters/mini.regular.v16.log b/test-tap/reporters/mini.regular.v16.log index 985df31c0..ab42c72f6 100644 --- a/test-tap/reporters/mini.regular.v16.log +++ b/test-tap/reporters/mini.regular.v16.log @@ -163,17 +163,17 @@ 1 skipped 1 todo---tty-stream-chunk-separator ---tty-stream-chunk-separator -[?25h ✖ No tests found in bad-test-chain.js +[?25h ✖ No tests found in bad-test-chain.cjs ─ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -192,17 +192,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -215,13 +215,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -229,13 +229,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -243,7 +243,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -258,7 +258,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -266,13 +266,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -283,13 +283,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -302,13 +302,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -328,16 +328,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -357,10 +357,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -374,7 +374,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -390,15 +390,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -410,15 +410,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -430,15 +430,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -450,15 +450,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -474,14 +474,14 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -489,13 +489,13 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -503,13 +503,13 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -517,11 +517,11 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null diff --git a/test-tap/reporters/prefix-title.js b/test-tap/reporters/prefix-title.js index 37ea8ded8..139342e14 100644 --- a/test-tap/reporters/prefix-title.js +++ b/test-tap/reporters/prefix-title.js @@ -1,50 +1,49 @@ -'use strict'; -require('../../lib/chalk').set(); +import path from 'path'; -const path = require('path'); -const figures = require('figures'); -const {test} = require('tap'); -const chalk = require('../../lib/chalk').get(); -const prefixTitle = require('../../lib/reporters/prefix-title'); +import figures from 'figures'; +import {test} from 'tap'; + +import {chalk} from '../../lib/chalk.js'; +import prefixTitle from '../../lib/reporters/prefix-title.js'; const sep = ' ' + chalk.gray.dim(figures.pointerSmall) + ' '; test('removes base if found at start of path', t => { - t.equal(prefixTitle(`test${path.sep}`, path.normalize('test/run-status.js'), 'title'), `run-status${sep}title`); + t.equal(prefixTitle(['cjs'], `test${path.sep}`, path.normalize('test/run-status.cjs'), 'title'), `run-status${sep}title`); t.end(); }); test('does not remove base if found but not at start of path', t => { - t.equal(prefixTitle(path.sep, path.normalize('test/run-status.js'), 'title'), `test${sep}run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, path.normalize('test/run-status.cjs'), 'title'), `test${sep}run-status${sep}title`); t.end(); }); test('removes .js extension', t => { - t.equal(prefixTitle(path.sep, 'run-status.js', 'title'), `run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, 'run-status.cjs', 'title'), `run-status${sep}title`); t.end(); }); test('does not remove .js from middle of path', t => { - t.equal(prefixTitle(path.sep, 'run-.js-status.js', 'title'), `run-.js-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, 'run-.js-status.cjs', 'title'), `run-.js-status${sep}title`); t.end(); }); test('removes __tests__ from path', t => { - t.equal(prefixTitle(path.sep, path.normalize('backend/__tests__/run-status.js'), 'title'), `backend${sep}run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, path.normalize('backend/__tests__/run-status.cjs'), 'title'), `backend${sep}run-status${sep}title`); t.end(); }); test('removes .spec from path', t => { - t.equal(prefixTitle(path.sep, path.normalize('backend/run-status.spec.js'), 'title'), `backend${sep}run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, path.normalize('backend/run-status.spec.cjs'), 'title'), `backend${sep}run-status${sep}title`); t.end(); }); test('removes .test from path', t => { - t.equal(prefixTitle(path.sep, path.normalize('backend/run-status.test.js'), 'title'), `backend${sep}run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, path.normalize('backend/run-status.test.cjs'), 'title'), `backend${sep}run-status${sep}title`); t.end(); }); test('removes test- from path', t => { - t.equal(prefixTitle(path.sep, path.normalize('backend/test-run-status.js'), 'title'), `backend${sep}run-status${sep}title`); + t.equal(prefixTitle(['cjs'], path.sep, path.normalize('backend/test-run-status.cjs'), 'title'), `backend${sep}run-status${sep}title`); t.end(); }); diff --git a/test-tap/reporters/tap.edgecases.v12.log b/test-tap/reporters/tap.edgecases.v12.log index d8e0bf81a..48b063a80 100644 --- a/test-tap/reporters/tap.edgecases.v12.log +++ b/test-tap/reporters/tap.edgecases.v12.log @@ -1,6 +1,6 @@ TAP version 13 ---tty-stream-chunk-separator -not ok 1 - No tests found in ava-import-no-test-declaration.js +not ok 1 - No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator not ok 2 - TypeError: test is not a function --- @@ -8,21 +8,21 @@ not ok 2 - TypeError: test is not a function message: test is not a function at: >- Object. - (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ... ---tty-stream-chunk-separator -not ok 3 - import-and-use-test-member.js exited with a non-zero exit code: 1 +not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator -not ok 4 - No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file +not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator not ok 5 - Error: throws --- name: Error message: throws - at: 'Object. (test-tap/fixture/report/edgecases/throws.js:1:7)' + at: 'Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7)' ... ---tty-stream-chunk-separator -not ok 6 - throws.js exited with a non-zero exit code: 1 +not ok 6 - throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator 1..0 diff --git a/test-tap/reporters/tap.edgecases.v14.log b/test-tap/reporters/tap.edgecases.v14.log index d8e0bf81a..48b063a80 100644 --- a/test-tap/reporters/tap.edgecases.v14.log +++ b/test-tap/reporters/tap.edgecases.v14.log @@ -1,6 +1,6 @@ TAP version 13 ---tty-stream-chunk-separator -not ok 1 - No tests found in ava-import-no-test-declaration.js +not ok 1 - No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator not ok 2 - TypeError: test is not a function --- @@ -8,21 +8,21 @@ not ok 2 - TypeError: test is not a function message: test is not a function at: >- Object. - (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ... ---tty-stream-chunk-separator -not ok 3 - import-and-use-test-member.js exited with a non-zero exit code: 1 +not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator -not ok 4 - No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file +not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator not ok 5 - Error: throws --- name: Error message: throws - at: 'Object. (test-tap/fixture/report/edgecases/throws.js:1:7)' + at: 'Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7)' ... ---tty-stream-chunk-separator -not ok 6 - throws.js exited with a non-zero exit code: 1 +not ok 6 - throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator 1..0 diff --git a/test-tap/reporters/tap.edgecases.v16.log b/test-tap/reporters/tap.edgecases.v16.log index d8e0bf81a..48b063a80 100644 --- a/test-tap/reporters/tap.edgecases.v16.log +++ b/test-tap/reporters/tap.edgecases.v16.log @@ -1,6 +1,6 @@ TAP version 13 ---tty-stream-chunk-separator -not ok 1 - No tests found in ava-import-no-test-declaration.js +not ok 1 - No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator not ok 2 - TypeError: test is not a function --- @@ -8,21 +8,21 @@ not ok 2 - TypeError: test is not a function message: test is not a function at: >- Object. - (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ... ---tty-stream-chunk-separator -not ok 3 - import-and-use-test-member.js exited with a non-zero exit code: 1 +not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator -not ok 4 - No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file +not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator not ok 5 - Error: throws --- name: Error message: throws - at: 'Object. (test-tap/fixture/report/edgecases/throws.js:1:7)' + at: 'Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7)' ... ---tty-stream-chunk-separator -not ok 6 - throws.js exited with a non-zero exit code: 1 +not ok 6 - throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator 1..0 diff --git a/test-tap/reporters/tap.failfast.v12.log b/test-tap/reporters/tap.failfast.v12.log index 258c0deec..5b44649f1 100644 --- a/test-tap/reporters/tap.failfast.v12.log +++ b/test-tap/reporters/tap.failfast.v12.log @@ -5,7 +5,7 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast/a.js:3:22' + at: 'test-tap/fixture/report/failfast/a.cjs:3:22' ... ---tty-stream-chunk-separator diff --git a/test-tap/reporters/tap.failfast.v14.log b/test-tap/reporters/tap.failfast.v14.log index 258c0deec..5b44649f1 100644 --- a/test-tap/reporters/tap.failfast.v14.log +++ b/test-tap/reporters/tap.failfast.v14.log @@ -5,7 +5,7 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast/a.js:3:22' + at: 'test-tap/fixture/report/failfast/a.cjs:3:22' ... ---tty-stream-chunk-separator diff --git a/test-tap/reporters/tap.failfast.v16.log b/test-tap/reporters/tap.failfast.v16.log index 258c0deec..5b44649f1 100644 --- a/test-tap/reporters/tap.failfast.v16.log +++ b/test-tap/reporters/tap.failfast.v16.log @@ -5,7 +5,7 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast/a.js:3:22' + at: 'test-tap/fixture/report/failfast/a.cjs:3:22' ... ---tty-stream-chunk-separator diff --git a/test-tap/reporters/tap.failfast2.v12.log b/test-tap/reporters/tap.failfast2.v12.log index 854c9a8c0..c10c8cd9f 100644 --- a/test-tap/reporters/tap.failfast2.v12.log +++ b/test-tap/reporters/tap.failfast2.v12.log @@ -5,10 +5,10 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast2/a.js:3:22' + at: 'test-tap/fixture/report/failfast2/a.cjs:3:22' ... ---tty-stream-chunk-separator -# 1 test remaining in a.js +# 1 test remaining in a.cjs ---tty-stream-chunk-separator 1..2 diff --git a/test-tap/reporters/tap.failfast2.v14.log b/test-tap/reporters/tap.failfast2.v14.log index 854c9a8c0..c10c8cd9f 100644 --- a/test-tap/reporters/tap.failfast2.v14.log +++ b/test-tap/reporters/tap.failfast2.v14.log @@ -5,10 +5,10 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast2/a.js:3:22' + at: 'test-tap/fixture/report/failfast2/a.cjs:3:22' ... ---tty-stream-chunk-separator -# 1 test remaining in a.js +# 1 test remaining in a.cjs ---tty-stream-chunk-separator 1..2 diff --git a/test-tap/reporters/tap.failfast2.v16.log b/test-tap/reporters/tap.failfast2.v16.log index 854c9a8c0..c10c8cd9f 100644 --- a/test-tap/reporters/tap.failfast2.v16.log +++ b/test-tap/reporters/tap.failfast2.v16.log @@ -5,10 +5,10 @@ not ok 1 - a › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/failfast2/a.js:3:22' + at: 'test-tap/fixture/report/failfast2/a.cjs:3:22' ... ---tty-stream-chunk-separator -# 1 test remaining in a.js +# 1 test remaining in a.cjs ---tty-stream-chunk-separator 1..2 diff --git a/test-tap/reporters/tap.js b/test-tap/reporters/tap.js index 846f7f378..a953ec5e0 100644 --- a/test-tap/reporters/tap.js +++ b/test-tap/reporters/tap.js @@ -1,37 +1,43 @@ -'use strict'; -require('../helper/fix-reporter-env')(); - -const path = require('path'); -const {test} = require('tap'); -const TTYStream = require('../helper/tty-stream'); -const report = require('../helper/report'); -const TapReporter = require('../../lib/reporters/tap'); - -const run = (type, sanitizers = []) => t => { - t.plan(1); - - const logFile = path.join(__dirname, `tap.${type.toLowerCase()}.${process.version.split('.')[0]}.log`); - - const tty = new TTYStream({ - columns: 200, - sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers] - }); - const reporter = new TapReporter({ - projectDir: report.projectDir(type), - reportStream: tty, - stdStream: tty - }); - return report[type](reporter) - .then(() => { - tty.end(); - return tty.asBuffer(); - }) - .then(buffer => report.assert(t, logFile, buffer)) - .catch(t.threw); -}; - -test('verbose reporter - regular run', run('regular')); -test('verbose reporter - failFast run', run('failFast')); -test('verbose reporter - second failFast run', run('failFast2')); -test('verbose reporter - only run', run('only')); -test('mini reporter - edge cases', run('edgeCases')); +import {fileURLToPath} from 'url'; + +import {test} from 'tap'; + +import fixReporterEnv from '../helper/fix-reporter-env.js'; +import report from '../helper/report.js'; +import TTYStream from '../helper/tty-stream.js'; + +fixReporterEnv(); + +test(async t => { + const {default: TapReporter} = await import('../../lib/reporters/tap.js'); + + const run = (type, sanitizers = []) => t => { + t.plan(1); + + const logFile = fileURLToPath(new URL(`tap.${type.toLowerCase()}.${process.version.split('.')[0]}.log`, import.meta.url)); + + const tty = new TTYStream({ + columns: 200, + sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers] + }); + const reporter = new TapReporter({ + extensions: ['cjs'], + projectDir: report.projectDir(type), + reportStream: tty, + stdStream: tty + }); + return report[type](reporter) + .then(() => { + tty.end(); + return tty.asBuffer(); + }) + .then(buffer => report.assert(t, logFile, buffer)) + .catch(t.threw); + }; + + t.test('verbose reporter - regular run', run('regular')); + t.test('verbose reporter - failFast run', run('failFast')); + t.test('verbose reporter - second failFast run', run('failFast2')); + t.test('verbose reporter - only run', run('only')); + t.test('mini reporter - edge cases', run('edgeCases')); +}); diff --git a/test-tap/reporters/tap.regular.v12.log b/test-tap/reporters/tap.regular.v12.log index a8ab2f46a..4092bcc26 100644 --- a/test-tap/reporters/tap.regular.v12.log +++ b/test-tap/reporters/tap.regular.v12.log @@ -4,10 +4,10 @@ not ok 1 - TypeError: test.serial.test is not a function --- name: TypeError message: test.serial.test is not a function - at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13)' + at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13)' ... ---tty-stream-chunk-separator -not ok 2 - bad-test-chain.js exited with a non-zero exit code: 1 +not ok 2 - bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator not ok 3 - nested-objects › format with max depth 4 --- @@ -29,7 +29,7 @@ not ok 3 - nested-objects › format with max depth 4 + }, + }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:28:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:29:4' ... ---tty-stream-chunk-separator not ok 4 - nested-objects › format like with max depth 4 @@ -46,7 +46,7 @@ not ok 4 - nested-objects › format like with max depth 4 }, }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:54:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:55:4' ... ---tty-stream-chunk-separator # output-in-hook › before hook @@ -70,7 +70,7 @@ not ok 6 - output-in-hook › failing test name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/output-in-hook.js:34:4' + at: 'test-tap/fixture/report/regular/output-in-hook.cjs:34:4' ... ---tty-stream-chunk-separator # output-in-hook › afterEach hook for passing test @@ -100,7 +100,7 @@ not ok 10 - test › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:9:22' + at: 'test-tap/fixture/report/regular/test.cjs:9:22' ... ---tty-stream-chunk-separator ok 11 - test › known failure @@ -121,7 +121,7 @@ not ok 13 - test › logs name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:18:4' + at: 'test-tap/fixture/report/regular/test.cjs:18:4' ... ---tty-stream-chunk-separator not ok 14 - test › formatted @@ -132,7 +132,7 @@ not ok 14 - test › formatted 'Difference:': |- - 'foo' + 'bar' - at: 'test-tap/fixture/report/regular/test.js:22:4' + at: 'test-tap/fixture/report/regular/test.cjs:22:4' ... ---tty-stream-chunk-separator not ok 15 - test › power-assert @@ -142,7 +142,7 @@ not ok 15 - test › power-assert operator: '!!' values: 'Value is not truthy:': '''''' - at: 'test-tap/fixture/report/regular/test.js:27:4' + at: 'test-tap/fixture/report/regular/test.cjs:27:4' ... ---tty-stream-chunk-separator not ok 16 - test › bad throws @@ -156,8 +156,8 @@ not ok 16 - test › bad throws message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:32:9) - test-tap/fixture/report/regular/test.js:35:11 + fn (test-tap/fixture/report/regular/test.cjs:32:9) + test-tap/fixture/report/regular/test.cjs:35:11 ... ---tty-stream-chunk-separator not ok 17 - test › bad notThrows @@ -171,8 +171,8 @@ not ok 17 - test › bad notThrows message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:40:9) - test-tap/fixture/report/regular/test.js:43:14 + fn (test-tap/fixture/report/regular/test.cjs:40:9) + test-tap/fixture/report/regular/test.cjs:43:14 ... ---tty-stream-chunk-separator not ok 18 - test › implementation throws non-error @@ -195,9 +195,9 @@ not ok 19 - traces-in-t-throws › throws } 'Expected instance of:': 'Function TypeError {}' at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 ... ---tty-stream-chunk-separator not ok 20 - traces-in-t-throws › notThrows @@ -210,9 +210,9 @@ not ok 20 - traces-in-t-throws › notThrows message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 ... ---tty-stream-chunk-separator not ok 21 - traces-in-t-throws › notThrowsAsync @@ -225,9 +225,9 @@ not ok 21 - traces-in-t-throws › notThrowsAsync message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 ... ---tty-stream-chunk-separator not ok 22 - traces-in-t-throws › throwsAsync @@ -240,12 +240,12 @@ not ok 22 - traces-in-t-throws › throwsAsync message: 'uh-oh', } at: >- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) t.throwsAsync.instanceOf - (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) - test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 ... ---tty-stream-chunk-separator not ok 23 - traces-in-t-throws › throwsAsync different error @@ -260,9 +260,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error 'Expected instance of:': 'Function TypeError {}' at: >- returnRejectedPromise - (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) - test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ... ---tty-stream-chunk-separator ok 24 - uncaught-exception › passes @@ -273,10 +273,10 @@ not ok 25 - Error: Can’t catch me message: Can’t catch me at: >- Immediate. - (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ... ---tty-stream-chunk-separator -not ok 26 - uncaught-exception.js exited with a non-zero exit code: 1 +not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ok 27 - unhandled-rejection › passes ---tty-stream-chunk-separator @@ -286,7 +286,7 @@ not ok 29 - Error: Can’t catch me --- name: Error message: Can’t catch me - at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17)' + at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)' ... ---tty-stream-chunk-separator not ok 30 - unhandled-rejection diff --git a/test-tap/reporters/tap.regular.v14.log b/test-tap/reporters/tap.regular.v14.log index a8ab2f46a..4092bcc26 100644 --- a/test-tap/reporters/tap.regular.v14.log +++ b/test-tap/reporters/tap.regular.v14.log @@ -4,10 +4,10 @@ not ok 1 - TypeError: test.serial.test is not a function --- name: TypeError message: test.serial.test is not a function - at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13)' + at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13)' ... ---tty-stream-chunk-separator -not ok 2 - bad-test-chain.js exited with a non-zero exit code: 1 +not ok 2 - bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator not ok 3 - nested-objects › format with max depth 4 --- @@ -29,7 +29,7 @@ not ok 3 - nested-objects › format with max depth 4 + }, + }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:28:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:29:4' ... ---tty-stream-chunk-separator not ok 4 - nested-objects › format like with max depth 4 @@ -46,7 +46,7 @@ not ok 4 - nested-objects › format like with max depth 4 }, }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:54:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:55:4' ... ---tty-stream-chunk-separator # output-in-hook › before hook @@ -70,7 +70,7 @@ not ok 6 - output-in-hook › failing test name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/output-in-hook.js:34:4' + at: 'test-tap/fixture/report/regular/output-in-hook.cjs:34:4' ... ---tty-stream-chunk-separator # output-in-hook › afterEach hook for passing test @@ -100,7 +100,7 @@ not ok 10 - test › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:9:22' + at: 'test-tap/fixture/report/regular/test.cjs:9:22' ... ---tty-stream-chunk-separator ok 11 - test › known failure @@ -121,7 +121,7 @@ not ok 13 - test › logs name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:18:4' + at: 'test-tap/fixture/report/regular/test.cjs:18:4' ... ---tty-stream-chunk-separator not ok 14 - test › formatted @@ -132,7 +132,7 @@ not ok 14 - test › formatted 'Difference:': |- - 'foo' + 'bar' - at: 'test-tap/fixture/report/regular/test.js:22:4' + at: 'test-tap/fixture/report/regular/test.cjs:22:4' ... ---tty-stream-chunk-separator not ok 15 - test › power-assert @@ -142,7 +142,7 @@ not ok 15 - test › power-assert operator: '!!' values: 'Value is not truthy:': '''''' - at: 'test-tap/fixture/report/regular/test.js:27:4' + at: 'test-tap/fixture/report/regular/test.cjs:27:4' ... ---tty-stream-chunk-separator not ok 16 - test › bad throws @@ -156,8 +156,8 @@ not ok 16 - test › bad throws message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:32:9) - test-tap/fixture/report/regular/test.js:35:11 + fn (test-tap/fixture/report/regular/test.cjs:32:9) + test-tap/fixture/report/regular/test.cjs:35:11 ... ---tty-stream-chunk-separator not ok 17 - test › bad notThrows @@ -171,8 +171,8 @@ not ok 17 - test › bad notThrows message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:40:9) - test-tap/fixture/report/regular/test.js:43:14 + fn (test-tap/fixture/report/regular/test.cjs:40:9) + test-tap/fixture/report/regular/test.cjs:43:14 ... ---tty-stream-chunk-separator not ok 18 - test › implementation throws non-error @@ -195,9 +195,9 @@ not ok 19 - traces-in-t-throws › throws } 'Expected instance of:': 'Function TypeError {}' at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 ... ---tty-stream-chunk-separator not ok 20 - traces-in-t-throws › notThrows @@ -210,9 +210,9 @@ not ok 20 - traces-in-t-throws › notThrows message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 ... ---tty-stream-chunk-separator not ok 21 - traces-in-t-throws › notThrowsAsync @@ -225,9 +225,9 @@ not ok 21 - traces-in-t-throws › notThrowsAsync message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 ... ---tty-stream-chunk-separator not ok 22 - traces-in-t-throws › throwsAsync @@ -240,12 +240,12 @@ not ok 22 - traces-in-t-throws › throwsAsync message: 'uh-oh', } at: >- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) t.throwsAsync.instanceOf - (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) - test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 ... ---tty-stream-chunk-separator not ok 23 - traces-in-t-throws › throwsAsync different error @@ -260,9 +260,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error 'Expected instance of:': 'Function TypeError {}' at: >- returnRejectedPromise - (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) - test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ... ---tty-stream-chunk-separator ok 24 - uncaught-exception › passes @@ -273,10 +273,10 @@ not ok 25 - Error: Can’t catch me message: Can’t catch me at: >- Immediate. - (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ... ---tty-stream-chunk-separator -not ok 26 - uncaught-exception.js exited with a non-zero exit code: 1 +not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ok 27 - unhandled-rejection › passes ---tty-stream-chunk-separator @@ -286,7 +286,7 @@ not ok 29 - Error: Can’t catch me --- name: Error message: Can’t catch me - at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17)' + at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)' ... ---tty-stream-chunk-separator not ok 30 - unhandled-rejection diff --git a/test-tap/reporters/tap.regular.v16.log b/test-tap/reporters/tap.regular.v16.log index a8ab2f46a..4092bcc26 100644 --- a/test-tap/reporters/tap.regular.v16.log +++ b/test-tap/reporters/tap.regular.v16.log @@ -4,10 +4,10 @@ not ok 1 - TypeError: test.serial.test is not a function --- name: TypeError message: test.serial.test is not a function - at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13)' + at: 'Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13)' ... ---tty-stream-chunk-separator -not ok 2 - bad-test-chain.js exited with a non-zero exit code: 1 +not ok 2 - bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator not ok 3 - nested-objects › format with max depth 4 --- @@ -29,7 +29,7 @@ not ok 3 - nested-objects › format with max depth 4 + }, + }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:28:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:29:4' ... ---tty-stream-chunk-separator not ok 4 - nested-objects › format like with max depth 4 @@ -46,7 +46,7 @@ not ok 4 - nested-objects › format like with max depth 4 }, }, } - at: 'test-tap/fixture/report/regular/nested-objects.js:54:4' + at: 'test-tap/fixture/report/regular/nested-objects.cjs:55:4' ... ---tty-stream-chunk-separator # output-in-hook › before hook @@ -70,7 +70,7 @@ not ok 6 - output-in-hook › failing test name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/output-in-hook.js:34:4' + at: 'test-tap/fixture/report/regular/output-in-hook.cjs:34:4' ... ---tty-stream-chunk-separator # output-in-hook › afterEach hook for passing test @@ -100,7 +100,7 @@ not ok 10 - test › fails name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:9:22' + at: 'test-tap/fixture/report/regular/test.cjs:9:22' ... ---tty-stream-chunk-separator ok 11 - test › known failure @@ -121,7 +121,7 @@ not ok 13 - test › logs name: AssertionError message: Test failed via `t.fail()` assertion: fail - at: 'test-tap/fixture/report/regular/test.js:18:4' + at: 'test-tap/fixture/report/regular/test.cjs:18:4' ... ---tty-stream-chunk-separator not ok 14 - test › formatted @@ -132,7 +132,7 @@ not ok 14 - test › formatted 'Difference:': |- - 'foo' + 'bar' - at: 'test-tap/fixture/report/regular/test.js:22:4' + at: 'test-tap/fixture/report/regular/test.cjs:22:4' ... ---tty-stream-chunk-separator not ok 15 - test › power-assert @@ -142,7 +142,7 @@ not ok 15 - test › power-assert operator: '!!' values: 'Value is not truthy:': '''''' - at: 'test-tap/fixture/report/regular/test.js:27:4' + at: 'test-tap/fixture/report/regular/test.cjs:27:4' ... ---tty-stream-chunk-separator not ok 16 - test › bad throws @@ -156,8 +156,8 @@ not ok 16 - test › bad throws message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:32:9) - test-tap/fixture/report/regular/test.js:35:11 + fn (test-tap/fixture/report/regular/test.cjs:32:9) + test-tap/fixture/report/regular/test.cjs:35:11 ... ---tty-stream-chunk-separator not ok 17 - test › bad notThrows @@ -171,8 +171,8 @@ not ok 17 - test › bad notThrows message: 'err', } at: |- - fn (test-tap/fixture/report/regular/test.js:40:9) - test-tap/fixture/report/regular/test.js:43:14 + fn (test-tap/fixture/report/regular/test.cjs:40:9) + test-tap/fixture/report/regular/test.cjs:43:14 ... ---tty-stream-chunk-separator not ok 18 - test › implementation throws non-error @@ -195,9 +195,9 @@ not ok 19 - traces-in-t-throws › throws } 'Expected instance of:': 'Function TypeError {}' at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 ... ---tty-stream-chunk-separator not ok 20 - traces-in-t-throws › notThrows @@ -210,9 +210,9 @@ not ok 20 - traces-in-t-throws › notThrows message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 ... ---tty-stream-chunk-separator not ok 21 - traces-in-t-throws › notThrowsAsync @@ -225,9 +225,9 @@ not ok 21 - traces-in-t-throws › notThrowsAsync message: 'uh-oh', } at: |- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 ... ---tty-stream-chunk-separator not ok 22 - traces-in-t-throws › throwsAsync @@ -240,12 +240,12 @@ not ok 22 - traces-in-t-throws › throwsAsync message: 'uh-oh', } at: >- - throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) + throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) t.throwsAsync.instanceOf - (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) - test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 ... ---tty-stream-chunk-separator not ok 23 - traces-in-t-throws › throwsAsync different error @@ -260,9 +260,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error 'Expected instance of:': 'Function TypeError {}' at: >- returnRejectedPromise - (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) + (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) - test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ... ---tty-stream-chunk-separator ok 24 - uncaught-exception › passes @@ -273,10 +273,10 @@ not ok 25 - Error: Can’t catch me message: Can’t catch me at: >- Immediate. - (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ... ---tty-stream-chunk-separator -not ok 26 - uncaught-exception.js exited with a non-zero exit code: 1 +not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ok 27 - unhandled-rejection › passes ---tty-stream-chunk-separator @@ -286,7 +286,7 @@ not ok 29 - Error: Can’t catch me --- name: Error message: Can’t catch me - at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17)' + at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)' ... ---tty-stream-chunk-separator not ok 30 - unhandled-rejection diff --git a/test-tap/reporters/verbose.edgecases.v12.log b/test-tap/reporters/verbose.edgecases.v12.log index 8d5fad418..1bf4d6825 100644 --- a/test-tap/reporters/verbose.edgecases.v12.log +++ b/test-tap/reporters/verbose.edgecases.v12.log @@ -1,15 +1,15 @@ ---tty-stream-chunk-separator - ⚠ Could not parse ast-syntax-error.js for line number selection + ⚠ Could not parse ast-syntax-error.cjs for line number selection ---tty-stream-chunk-separator - ✖ Line numbers for ast-syntax-error.js did not match any tests + ✖ Line numbers for ast-syntax-error.cjs did not match any tests ---tty-stream-chunk-separator - ✖ No tests found in ava-import-no-test-declaration.js + ✖ No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -17,29 +17,29 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ---tty-stream-chunk-separator - ✖ import-and-use-test-member.js exited with a non-zero exit code: 1 + ✖ import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator - ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file + ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator - ✖ Line numbers for test.js did not match any tests + ✖ Line numbers for test.cjs did not match any tests ---tty-stream-chunk-separator - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ---tty-stream-chunk-separator - ✖ throws.js exited with a non-zero exit code: 1 + ✖ throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ─ diff --git a/test-tap/reporters/verbose.edgecases.v14.log b/test-tap/reporters/verbose.edgecases.v14.log index 8d5fad418..1bf4d6825 100644 --- a/test-tap/reporters/verbose.edgecases.v14.log +++ b/test-tap/reporters/verbose.edgecases.v14.log @@ -1,15 +1,15 @@ ---tty-stream-chunk-separator - ⚠ Could not parse ast-syntax-error.js for line number selection + ⚠ Could not parse ast-syntax-error.cjs for line number selection ---tty-stream-chunk-separator - ✖ Line numbers for ast-syntax-error.js did not match any tests + ✖ Line numbers for ast-syntax-error.cjs did not match any tests ---tty-stream-chunk-separator - ✖ No tests found in ava-import-no-test-declaration.js + ✖ No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -17,29 +17,29 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ---tty-stream-chunk-separator - ✖ import-and-use-test-member.js exited with a non-zero exit code: 1 + ✖ import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator - ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file + ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator - ✖ Line numbers for test.js did not match any tests + ✖ Line numbers for test.cjs did not match any tests ---tty-stream-chunk-separator - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ---tty-stream-chunk-separator - ✖ throws.js exited with a non-zero exit code: 1 + ✖ throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ─ diff --git a/test-tap/reporters/verbose.edgecases.v16.log b/test-tap/reporters/verbose.edgecases.v16.log index 8d5fad418..1bf4d6825 100644 --- a/test-tap/reporters/verbose.edgecases.v16.log +++ b/test-tap/reporters/verbose.edgecases.v16.log @@ -1,15 +1,15 @@ ---tty-stream-chunk-separator - ⚠ Could not parse ast-syntax-error.js for line number selection + ⚠ Could not parse ast-syntax-error.cjs for line number selection ---tty-stream-chunk-separator - ✖ Line numbers for ast-syntax-error.js did not match any tests + ✖ Line numbers for ast-syntax-error.cjs did not match any tests ---tty-stream-chunk-separator - ✖ No tests found in ava-import-no-test-declaration.js + ✖ No tests found in ava-import-no-test-declaration.cjs ---tty-stream-chunk-separator - Uncaught exception in import-and-use-test-member.js + Uncaught exception in import-and-use-test-member.cjs - import-and-use-test-member.js:3 + import-and-use-test-member.cjs:3 2:  3: test('pass', t => t.pass()); @@ -17,29 +17,29 @@ TypeError: test is not a function - › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.js:3:1) + › Object. (test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1) ---tty-stream-chunk-separator - ✖ import-and-use-test-member.js exited with a non-zero exit code: 1 + ✖ import-and-use-test-member.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator - ✖ No tests found in no-ava-import.js, make sure to import "ava" at the top of your test file + ✖ No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file ---tty-stream-chunk-separator - ✖ Line numbers for test.js did not match any tests + ✖ Line numbers for test.cjs did not match any tests ---tty-stream-chunk-separator - Uncaught exception in throws.js + Uncaught exception in throws.cjs - throws.js:1 + throws.cjs:1  1: throw new Error('throws'); 2: Error: throws - › Object. (test-tap/fixture/report/edgecases/throws.js:1:7) + › Object. (test-tap/fixture/report/edgecases/throws.cjs:1:7) ---tty-stream-chunk-separator - ✖ throws.js exited with a non-zero exit code: 1 + ✖ throws.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ─ diff --git a/test-tap/reporters/verbose.failfast.v12.log b/test-tap/reporters/verbose.failfast.v12.log index a9414f802..831e81f6c 100644 --- a/test-tap/reporters/verbose.failfast.v12.log +++ b/test-tap/reporters/verbose.failfast.v12.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.failfast.v14.log b/test-tap/reporters/verbose.failfast.v14.log index a9414f802..831e81f6c 100644 --- a/test-tap/reporters/verbose.failfast.v14.log +++ b/test-tap/reporters/verbose.failfast.v14.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.failfast.v16.log b/test-tap/reporters/verbose.failfast.v16.log index a9414f802..831e81f6c 100644 --- a/test-tap/reporters/verbose.failfast.v16.log +++ b/test-tap/reporters/verbose.failfast.v16.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail()); @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast/a.js:3:22 + › test-tap/fixture/report/failfast/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.failfast2.v12.log b/test-tap/reporters/verbose.failfast2.v12.log index e04170b8a..22d9cd398 100644 --- a/test-tap/reporters/verbose.failfast2.v12.log +++ b/test-tap/reporters/verbose.failfast2.v12.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.failfast2.v14.log b/test-tap/reporters/verbose.failfast2.v14.log index e04170b8a..22d9cd398 100644 --- a/test-tap/reporters/verbose.failfast2.v14.log +++ b/test-tap/reporters/verbose.failfast2.v14.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.failfast2.v16.log b/test-tap/reporters/verbose.failfast2.v16.log index e04170b8a..22d9cd398 100644 --- a/test-tap/reporters/verbose.failfast2.v16.log +++ b/test-tap/reporters/verbose.failfast2.v16.log @@ -6,7 +6,7 @@ a › fails - a.js:3 + a.cjs:3 2:  3: test('fails', t => t.fail());  @@ -14,7 +14,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/failfast2/a.js:3:22 + › test-tap/fixture/report/failfast2/a.cjs:3:22 ─ diff --git a/test-tap/reporters/verbose.js b/test-tap/reporters/verbose.js index 3cf6f800b..63e381dfd 100644 --- a/test-tap/reporters/verbose.js +++ b/test-tap/reporters/verbose.js @@ -1,50 +1,57 @@ -'use strict'; -const path = require('path'); -const {test} = require('tap'); -const {restoreClock} = require('../helper/fix-reporter-env')(); -const TTYStream = require('../helper/tty-stream'); -const report = require('../helper/report'); -const Reporter = require('../../lib/reporters/default'); - -const run = (type, sanitizers = []) => t => { - t.plan(1); - - const logFile = path.join(__dirname, `verbose.${type.toLowerCase()}.${process.version.split('.')[0]}.log`); - - const tty = new TTYStream({ - columns: 200, - sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers, report.sanitizers.version] - }); - const reporter = new Reporter({ - projectDir: report.projectDir(type), - durationThreshold: 60000, - reportStream: tty, - stdStream: tty, - verbose: true, - watching: type === 'watch' - }); +import {fileURLToPath} from 'url'; + +import {test} from 'tap'; + +import fixReporterEnv from '../helper/fix-reporter-env.js'; +import report from '../helper/report.js'; +import TTYStream from '../helper/tty-stream.js'; + +const {restoreClock} = fixReporterEnv(); + +test(async t => { + const {default: Reporter} = await import('../../lib/reporters/default.js'); + + const run = (type, sanitizers = []) => t => { + t.plan(1); - return report[type](reporter) - .then(() => { - tty.end(); - return tty.asBuffer(); - }) - .then(buffer => report.assert(t, logFile, buffer)) - .catch(t.threw); -}; - -test('verbose reporter - regular run', run('regular')); -test('verbose reporter - failFast run', run('failFast')); -test('verbose reporter - second failFast run', run('failFast2')); -test('verbose reporter - only run', run('only')); -test('verbose reporter - watch mode run', run('watch')); -test('verbose reporter - edge cases', run('edgeCases')); - -test('verbose reporter - timeout', t => { - restoreClock(); - - t.test('single file run', run('timeoutInSingleFile')); - t.test('multiple files run', run('timeoutInMultipleFiles')); - t.test('single file with only certain tests matched run', run('timeoutWithMatch')); - t.end(); + const logFile = fileURLToPath(new URL(`verbose.${type.toLowerCase()}.${process.version.split('.')[0]}.log`, import.meta.url)); + + const tty = new TTYStream({ + columns: 200, + sanitizers: [...sanitizers, report.sanitizers.cwd, report.sanitizers.experimentalWarning, report.sanitizers.posix, report.sanitizers.timers, report.sanitizers.version] + }); + const reporter = new Reporter({ + extensions: ['cjs'], + projectDir: report.projectDir(type), + durationThreshold: 60000, + reportStream: tty, + stdStream: tty, + verbose: true, + watching: type === 'watch' + }); + + return report[type](reporter) + .then(() => { + tty.end(); + return tty.asBuffer(); + }) + .then(buffer => report.assert(t, logFile, buffer)) + .catch(t.threw); + }; + + t.test('verbose reporter - regular run', run('regular')); + t.test('verbose reporter - failFast run', run('failFast')); + t.test('verbose reporter - second failFast run', run('failFast2')); + t.test('verbose reporter - only run', run('only')); + t.test('verbose reporter - watch mode run', run('watch')); + t.test('verbose reporter - edge cases', run('edgeCases')); + + t.test('verbose reporter - timeout', t => { + restoreClock(); + + t.test('single file run', run('timeoutInSingleFile')); + t.test('multiple files run', run('timeoutInMultipleFiles')); + t.test('single file with only certain tests matched run', run('timeoutWithMatch')); + t.end(); + }); }); diff --git a/test-tap/reporters/verbose.regular.v12.log b/test-tap/reporters/verbose.regular.v12.log index 6e87f9b7f..91b601ed8 100644 --- a/test-tap/reporters/verbose.regular.v12.log +++ b/test-tap/reporters/verbose.regular.v12.log @@ -1,8 +1,8 @@ ---tty-stream-chunk-separator - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -10,10 +10,10 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) ---tty-stream-chunk-separator - ✖ bad-test-chain.js exited with a non-zero exit code: 1 + ✖ bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✖ nested-objects › format with max depth 4 ---tty-stream-chunk-separator @@ -83,9 +83,9 @@ ✔ uncaught-exception › passes ---tty-stream-chunk-separator - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -93,19 +93,19 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ---tty-stream-chunk-separator - ✖ uncaught-exception.js exited with a non-zero exit code: 1 + ✖ uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✔ unhandled-rejection › passes ---tty-stream-chunk-separator ✔ unhandled-rejection › unhandled non-error rejection ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -113,10 +113,10 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null @@ -125,11 +125,11 @@ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -148,17 +148,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -171,13 +171,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -185,13 +185,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -199,7 +199,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -214,7 +214,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -222,13 +222,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -239,13 +239,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -258,13 +258,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -284,16 +284,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -313,10 +313,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -330,7 +330,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -346,15 +346,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -366,15 +366,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -386,15 +386,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -406,15 +406,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -430,8 +430,8 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ─ diff --git a/test-tap/reporters/verbose.regular.v14.log b/test-tap/reporters/verbose.regular.v14.log index 6e87f9b7f..91b601ed8 100644 --- a/test-tap/reporters/verbose.regular.v14.log +++ b/test-tap/reporters/verbose.regular.v14.log @@ -1,8 +1,8 @@ ---tty-stream-chunk-separator - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -10,10 +10,10 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) ---tty-stream-chunk-separator - ✖ bad-test-chain.js exited with a non-zero exit code: 1 + ✖ bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✖ nested-objects › format with max depth 4 ---tty-stream-chunk-separator @@ -83,9 +83,9 @@ ✔ uncaught-exception › passes ---tty-stream-chunk-separator - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -93,19 +93,19 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ---tty-stream-chunk-separator - ✖ uncaught-exception.js exited with a non-zero exit code: 1 + ✖ uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✔ unhandled-rejection › passes ---tty-stream-chunk-separator ✔ unhandled-rejection › unhandled non-error rejection ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -113,10 +113,10 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null @@ -125,11 +125,11 @@ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -148,17 +148,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -171,13 +171,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -185,13 +185,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -199,7 +199,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -214,7 +214,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -222,13 +222,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -239,13 +239,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -258,13 +258,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -284,16 +284,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -313,10 +313,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -330,7 +330,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -346,15 +346,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -366,15 +366,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -386,15 +386,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -406,15 +406,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -430,8 +430,8 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ─ diff --git a/test-tap/reporters/verbose.regular.v16.log b/test-tap/reporters/verbose.regular.v16.log index 6e87f9b7f..91b601ed8 100644 --- a/test-tap/reporters/verbose.regular.v16.log +++ b/test-tap/reporters/verbose.regular.v16.log @@ -1,8 +1,8 @@ ---tty-stream-chunk-separator - Uncaught exception in bad-test-chain.js + Uncaught exception in bad-test-chain.cjs - bad-test-chain.js:3 + bad-test-chain.cjs:3 2:  3: test.serial.test('passes', t => t.pass()); @@ -10,10 +10,10 @@ TypeError: test.serial.test is not a function - › Object. (test-tap/fixture/report/regular/bad-test-chain.js:3:13) + › Object. (test-tap/fixture/report/regular/bad-test-chain.cjs:3:13) ---tty-stream-chunk-separator - ✖ bad-test-chain.js exited with a non-zero exit code: 1 + ✖ bad-test-chain.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✖ nested-objects › format with max depth 4 ---tty-stream-chunk-separator @@ -83,9 +83,9 @@ ✔ uncaught-exception › passes ---tty-stream-chunk-separator - Uncaught exception in uncaught-exception.js + Uncaught exception in uncaught-exception.cjs - uncaught-exception.js:5 + uncaught-exception.cjs:5 4: setImmediate(() => {  5: throw new Error('Can’t catch me'); @@ -93,19 +93,19 @@ Error: Can’t catch me - › Immediate. (test-tap/fixture/report/regular/uncaught-exception.js:5:9) + › Immediate. (test-tap/fixture/report/regular/uncaught-exception.cjs:5:9) ---tty-stream-chunk-separator - ✖ uncaught-exception.js exited with a non-zero exit code: 1 + ✖ uncaught-exception.cjs exited with a non-zero exit code: 1 ---tty-stream-chunk-separator ✔ unhandled-rejection › passes ---tty-stream-chunk-separator ✔ unhandled-rejection › unhandled non-error rejection ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs - unhandled-rejection.js:4 + unhandled-rejection.cjs:4 3: const passes = t => {  4: Promise.reject(new Error('Can’t catch me')); @@ -113,10 +113,10 @@ Error: Can’t catch me - › passes (test-tap/fixture/report/regular/unhandled-rejection.js:4:17) + › passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17) ---tty-stream-chunk-separator - Unhandled rejection in unhandled-rejection.js + Unhandled rejection in unhandled-rejection.cjs null @@ -125,11 +125,11 @@ nested-objects › format with max depth 4 - nested-objects.js:28 + nested-objects.cjs:29 - 27: }; -  28: t.deepEqual(exp, act); - 29: }); + 28: }; +  29: t.deepEqual(exp, act); + 30: }); Difference: @@ -148,17 +148,17 @@ + }, } - › test-tap/fixture/report/regular/nested-objects.js:28:4 + › test-tap/fixture/report/regular/nested-objects.cjs:29:4 nested-objects › format like with max depth 4 - nested-objects.js:54 + nested-objects.cjs:55 - 53: }; -  54: t.like(actual, pattern); - 55: }); + 54: }; +  55: t.like(actual, pattern); + 56: }); Difference: @@ -171,13 +171,13 @@ }, } - › test-tap/fixture/report/regular/nested-objects.js:54:4 + › test-tap/fixture/report/regular/nested-objects.cjs:55:4 output-in-hook › failing test - output-in-hook.js:34 + output-in-hook.cjs:34 33: test('failing test', t => {  34: t.fail();  @@ -185,13 +185,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/output-in-hook.js:34:4 + › test-tap/fixture/report/regular/output-in-hook.cjs:34:4 test › fails - test.js:9 + test.cjs:9 8:  9: test('fails', t => t.fail()); @@ -199,7 +199,7 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:9:22 + › test-tap/fixture/report/regular/test.cjs:9:22 @@ -214,7 +214,7 @@ ℹ hello ℹ world - test.js:18 + test.cjs:18 17: t.log('world');  18: t.fail();  @@ -222,13 +222,13 @@ Test failed via `t.fail()` - › test-tap/fixture/report/regular/test.js:18:4 + › test-tap/fixture/report/regular/test.cjs:18:4 test › formatted - test.js:22 + test.cjs:22 21: test('formatted', t => {  22: t.deepEqual('foo', 'bar'); @@ -239,13 +239,13 @@ - 'foo' + 'bar' - › test-tap/fixture/report/regular/test.js:22:4 + › test-tap/fixture/report/regular/test.cjs:22:4 test › power-assert - test.js:27 + test.cjs:27 26: const foo = '';  27: t.assert(foo);  @@ -258,13 +258,13 @@ foo => '' - › test-tap/fixture/report/regular/test.js:27:4 + › test-tap/fixture/report/regular/test.cjs:27:4 test › bad throws - test.js:35 + test.cjs:35 34:  35: t.throws(fn()); @@ -284,16 +284,16 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:32:9) - › test-tap/fixture/report/regular/test.js:35:11 + › fn (test-tap/fixture/report/regular/test.cjs:32:9) + › test-tap/fixture/report/regular/test.cjs:35:11 test › bad notThrows - test.js:43 + test.cjs:43 42:  43: t.notThrows(fn()); @@ -313,10 +313,10 @@ Visit the following URL for more details: - https://github.com/avajs/ava/blob/v1.0.0-beta.5.1/docs/03-assertions.md#throwsfn-expected-message + https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message - › fn (test-tap/fixture/report/regular/test.js:40:9) - › test-tap/fixture/report/regular/test.js:43:14 + › fn (test-tap/fixture/report/regular/test.cjs:40:9) + › test-tap/fixture/report/regular/test.cjs:43:14 @@ -330,7 +330,7 @@ traces-in-t-throws › throws - traces-in-t-throws.js:12 + traces-in-t-throws.cjs:12 11: test('throws', t => {  12: t.throws(() => throwError(), {instanceOf: TypeError}); @@ -346,15 +346,15 @@ Function TypeError {} - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:17 - › test-tap/fixture/report/regular/traces-in-t-throws.js:12:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4 traces-in-t-throws › notThrows - traces-in-t-throws.js:16 + traces-in-t-throws.cjs:16 15: test('notThrows', t => {  16: t.notThrows(() => throwError()); @@ -366,15 +366,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:20 - › test-tap/fixture/report/regular/traces-in-t-throws.js:16:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:20 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4 traces-in-t-throws › notThrowsAsync - traces-in-t-throws.js:20 + traces-in-t-throws.cjs:20 19: test('notThrowsAsync', t => {  20: t.notThrowsAsync(() => throwError()); @@ -386,15 +386,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:25 - › test-tap/fixture/report/regular/traces-in-t-throws.js:20:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:25 + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4 traces-in-t-throws › throwsAsync - traces-in-t-throws.js:24 + traces-in-t-throws.cjs:24 23: test('throwsAsync', t => {  24: t.throwsAsync(() => throwError(), {instanceOf: TypeError}); @@ -406,15 +406,15 @@ message: 'uh-oh', } - › throwError (test-tap/fixture/report/regular/traces-in-t-throws.js:4:8) - › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.js:24:22) - › test-tap/fixture/report/regular/traces-in-t-throws.js:24:4 + › throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8) + › t.throwsAsync.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:22) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4 traces-in-t-throws › throwsAsync different error - traces-in-t-throws.js:28 + traces-in-t-throws.cjs:28 27: test('throwsAsync different error', t => {  28: return t.throwsAsync(returnRejectedPromise, {instanceOf: TypeError}); @@ -430,8 +430,8 @@ Function TypeError {} - › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.js:8:24) - › test-tap/fixture/report/regular/traces-in-t-throws.js:28:11 + › returnRejectedPromise (test-tap/fixture/report/regular/traces-in-t-throws.cjs:8:24) + › test-tap/fixture/report/regular/traces-in-t-throws.cjs:28:11 ─ diff --git a/test-tap/reporters/verbose.timeoutinmultiplefiles.v12.log b/test-tap/reporters/verbose.timeoutinmultiplefiles.v12.log index 50f1f1e5a..dbc999ffd 100644 --- a/test-tap/reporters/verbose.timeoutinmultiplefiles.v12.log +++ b/test-tap/reporters/verbose.timeoutinmultiplefiles.v12.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ a › a slow ◌ a › a slow two @@ -20,7 +20,7 @@  ✖ Timed out while running tests - 3 tests were pending in b.js + 3 tests were pending in b.cjs ◌ b › b slow ◌ b › b slow two diff --git a/test-tap/reporters/verbose.timeoutinmultiplefiles.v14.log b/test-tap/reporters/verbose.timeoutinmultiplefiles.v14.log index 50f1f1e5a..dbc999ffd 100644 --- a/test-tap/reporters/verbose.timeoutinmultiplefiles.v14.log +++ b/test-tap/reporters/verbose.timeoutinmultiplefiles.v14.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ a › a slow ◌ a › a slow two @@ -20,7 +20,7 @@  ✖ Timed out while running tests - 3 tests were pending in b.js + 3 tests were pending in b.cjs ◌ b › b slow ◌ b › b slow two diff --git a/test-tap/reporters/verbose.timeoutinmultiplefiles.v16.log b/test-tap/reporters/verbose.timeoutinmultiplefiles.v16.log index 50f1f1e5a..dbc999ffd 100644 --- a/test-tap/reporters/verbose.timeoutinmultiplefiles.v16.log +++ b/test-tap/reporters/verbose.timeoutinmultiplefiles.v16.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ a › a slow ◌ a › a slow two @@ -20,7 +20,7 @@  ✖ Timed out while running tests - 3 tests were pending in b.js + 3 tests were pending in b.cjs ◌ b › b slow ◌ b › b slow two diff --git a/test-tap/reporters/verbose.timeoutinsinglefile.v12.log b/test-tap/reporters/verbose.timeoutinsinglefile.v12.log index edc7e415d..43c2cbffa 100644 --- a/test-tap/reporters/verbose.timeoutinsinglefile.v12.log +++ b/test-tap/reporters/verbose.timeoutinsinglefile.v12.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow ◌ slow two diff --git a/test-tap/reporters/verbose.timeoutinsinglefile.v14.log b/test-tap/reporters/verbose.timeoutinsinglefile.v14.log index edc7e415d..43c2cbffa 100644 --- a/test-tap/reporters/verbose.timeoutinsinglefile.v14.log +++ b/test-tap/reporters/verbose.timeoutinsinglefile.v14.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow ◌ slow two diff --git a/test-tap/reporters/verbose.timeoutinsinglefile.v16.log b/test-tap/reporters/verbose.timeoutinsinglefile.v16.log index edc7e415d..43c2cbffa 100644 --- a/test-tap/reporters/verbose.timeoutinsinglefile.v16.log +++ b/test-tap/reporters/verbose.timeoutinsinglefile.v16.log @@ -7,7 +7,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow ◌ slow two diff --git a/test-tap/reporters/verbose.timeoutwithmatch.v12.log b/test-tap/reporters/verbose.timeoutwithmatch.v12.log index b40ca5cf8..e64e4e60f 100644 --- a/test-tap/reporters/verbose.timeoutwithmatch.v12.log +++ b/test-tap/reporters/verbose.timeoutwithmatch.v12.log @@ -5,7 +5,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow needle ◌ slow three needle diff --git a/test-tap/reporters/verbose.timeoutwithmatch.v14.log b/test-tap/reporters/verbose.timeoutwithmatch.v14.log index b40ca5cf8..e64e4e60f 100644 --- a/test-tap/reporters/verbose.timeoutwithmatch.v14.log +++ b/test-tap/reporters/verbose.timeoutwithmatch.v14.log @@ -5,7 +5,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow needle ◌ slow three needle diff --git a/test-tap/reporters/verbose.timeoutwithmatch.v16.log b/test-tap/reporters/verbose.timeoutwithmatch.v16.log index b40ca5cf8..e64e4e60f 100644 --- a/test-tap/reporters/verbose.timeoutwithmatch.v16.log +++ b/test-tap/reporters/verbose.timeoutwithmatch.v16.log @@ -5,7 +5,7 @@  ✖ Timed out while running tests - 2 tests were pending in a.js + 2 tests were pending in a.cjs ◌ slow needle ◌ slow three needle diff --git a/test-tap/runner.js b/test-tap/runner.js index 6e2adc174..91a85f826 100644 --- a/test-tap/runner.js +++ b/test-tap/runner.js @@ -1,10 +1,10 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({}); +import delay from 'delay'; +import {test} from 'tap'; -const delay = require('delay'); -const {test} = require('tap'); -const Runner = require('../lib/runner'); +import Runner from '../lib/runner.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +setOptions({}); const noop = () => {}; diff --git a/test-tap/serialize-error.js b/test-tap/serialize-error.js index e2469de76..5cad96e43 100644 --- a/test-tap/serialize-error.js +++ b/test-tap/serialize-error.js @@ -1,12 +1,12 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({}); +import {test} from 'tap'; -const {test} = require('tap'); -const avaAssert = require('../lib/assert'); -const serializeError = require('../lib/serialize-error'); +import * as avaAssert from '../lib/assert.js'; +import serializeError from '../lib/serialize-error.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; -const serialize = error => serializeError('Test', true, error, __filename); +setOptions({}); + +const serialize = error => serializeError('Test', true, error, import.meta.url); test('serialize standard props', t => { const error = new Error('Hello'); @@ -38,7 +38,7 @@ test('source file is an absolute path', t => { const error = new Error('Hello'); const serializedError = serialize(error); - t.equal(serializedError.source.file, __filename); + t.equal(serializedError.source.file, import.meta.url); t.end(); }); diff --git a/test-tap/test-try-commit.js b/test-tap/test-try-commit.js index a815aec64..152a9f9e2 100644 --- a/test-tap/test-try-commit.js +++ b/test-tap/test-try-commit.js @@ -1,11 +1,12 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({chalkOptions: {level: 0}}); - -const {test} = require('tap'); -const delay = require('delay'); -const ContextRef = require('../lib/context-ref'); -const {newAva} = require('./helper/ava-test'); +import delay from 'delay'; +import {test} from 'tap'; + +import ContextRef from '../lib/context-ref.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +import {newAva} from './helper/ava-test.js'; + +setOptions({chalkOptions: {level: 0}}); test('try-commit works', async t => { const ava = newAva(); diff --git a/test-tap/test.js b/test-tap/test.js index 112c777a0..9c0323d02 100644 --- a/test-tap/test.js +++ b/test-tap/test.js @@ -1,14 +1,18 @@ -'use strict'; -require('../lib/chalk').set({level: 0}); -require('../lib/worker/options').set({}); - -const path = require('path'); -const {test} = require('tap'); -const sinon = require('sinon'); -const delay = require('delay'); -const snapshotManager = require('../lib/snapshot-manager'); -const Test = require('../lib/test'); -const {ava} = require('./helper/ava-test'); +import path from 'path'; +import {fileURLToPath} from 'url'; + +import delay from 'delay'; +import sinon from 'sinon'; +import {test} from 'tap'; + +import './helper/chalk0.js'; // eslint-disable-line import/no-unassigned-import +import * as snapshotManager from '../lib/snapshot-manager.js'; +import Test from '../lib/test.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +import {ava} from './helper/ava-test.js'; + +setOptions({}); const failingTestHint = 'Test was expected to fail, but succeeded, you should stop marking the test as failing'; @@ -528,9 +532,9 @@ test('assertions are bound', t => { // Snapshots reused from test/assert.js test('snapshot assertion can be skipped', t => { - const projectDir = path.join(__dirname, 'fixture'); + const projectDir = fileURLToPath(new URL('fixture', import.meta.url)); const manager = snapshotManager.load({ - file: path.join(projectDir, 'assert.js'), + file: path.join(projectDir, 'assert.cjs'), projectDir, fixedLocation: null, recordNewSnapshots: true, @@ -554,9 +558,9 @@ test('snapshot assertion can be skipped', t => { // Snapshots reused from test/assert.js test('snapshot assertions call options.skipSnapshot when skipped', async t => { - const projectDir = path.join(__dirname, 'fixture'); + const projectDir = fileURLToPath(new URL('fixture', import.meta.url)); const manager = snapshotManager.load({ - file: path.join(projectDir, 'assert.js'), + file: path.join(projectDir, 'assert.cjs'), projectDir, fixedLocation: null, updating: false @@ -617,13 +621,13 @@ test('timeout with promise', t => { test('timeout is refreshed on assert', t => { return ava(async a => { - a.timeout(10); + a.timeout(100); a.plan(3); await Promise.all([ - delay(5).then(() => a.pass()), - delay(10).then(() => a.pass()), - delay(15).then(() => a.pass()), - delay(20) + delay(50).then(() => a.pass()), + delay(100).then(() => a.pass()), + delay(150).then(() => a.pass()), + delay(200) ]); }).run().then(result => { t.equal(result.passed, true); diff --git a/test-tap/try-snapshot.js b/test-tap/try-snapshot.js index c3da1a386..1c2b5f47c 100644 --- a/test-tap/try-snapshot.js +++ b/test-tap/try-snapshot.js @@ -1,12 +1,15 @@ -'use strict'; -require('../lib/chalk').set(); -require('../lib/worker/options').set({chalkOptions: {level: 0}}); +import path from 'path'; +import {fileURLToPath} from 'url'; -const path = require('path'); -const {test} = require('tap'); -const snapshotManager = require('../lib/snapshot-manager'); -const Test = require('../lib/test'); -const ContextRef = require('../lib/context-ref'); +import {test} from 'tap'; + +import './helper/chalk0.js'; // eslint-disable-line import/no-unassigned-import +import ContextRef from '../lib/context-ref.js'; +import * as snapshotManager from '../lib/snapshot-manager.js'; +import Test from '../lib/test.js'; +import {set as setOptions} from '../lib/worker/options.cjs'; + +setOptions({}); function setup(title, manager, fn) { return new Test({ @@ -28,9 +31,9 @@ test(async t => { // Ignore errors and make sure not to run tests with the `-b` (bail) option. const updating = false; - const projectDir = path.join(__dirname, 'fixture'); + const projectDir = fileURLToPath(new URL('fixture', import.meta.url)); const manager = snapshotManager.load({ - file: path.join(projectDir, 'try-snapshot.js'), + file: path.join(projectDir, 'try-snapshot.cjs'), projectDir, fixedLocation: null, updating, diff --git a/test-tap/watcher.js b/test-tap/watcher.js index b2bbfa970..3d8405ae9 100644 --- a/test-tap/watcher.js +++ b/test-tap/watcher.js @@ -1,16 +1,18 @@ -'use strict'; -const path = require('path'); -const EventEmitter = require('events'); -const {PassThrough} = require('stream'); -const fakeTimers = require('@sinonjs/fake-timers'); -const defaultIgnore = require('ignore-by-default').directories(); -const proxyquire = require('proxyquire'); -const sinon = require('sinon'); -const {test} = require('tap'); -const {normalizeGlobs} = require('../lib/globs'); -const {setImmediate} = require('../lib/now-and-timers'); - -require('../lib/chalk').set({}); +import EventEmitter from 'events'; +import path from 'path'; +import {PassThrough} from 'stream'; + +import fakeTimers from '@sinonjs/fake-timers'; +import ignoreByDefault from 'ignore-by-default'; +import sinon from 'sinon'; +import {test} from 'tap'; + +import {normalizeGlobs} from '../lib/globs.js'; +import timers from '../lib/now-and-timers.cjs'; +import Watcher, {_testOnlyReplaceChokidar, _testOnlyReplaceDebug} from '../lib/watcher.js'; + +const {setImmediate} = timers; +const defaultIgnore = ignoreByDefault.directories(); // Helper to make using beforeEach less arduous function makeGroup(test) { @@ -50,24 +52,14 @@ group('chokidar', (beforeEach, test, group) => { let files; let defaultApiOptions; - function proxyWatcher(options) { - return proxyquire.noCallThru().load('../lib/watcher', options || - { - chokidar, - debug(name) { - return (...args) => { - debug(...[name, ...args]); - }; - } - }); - } - beforeEach(() => { chokidar = { watch: sinon.stub() }; + _testOnlyReplaceChokidar(chokidar); debug = sinon.spy(); + _testOnlyReplaceDebug(name => (...args) => debug(name, ...args)); reporter = { endRun: sinon.spy(), @@ -124,9 +116,9 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(new Promise(() => {})); files = [ - 'test.js', - 'test-*.js', - 'test/**/*.js' + 'test.cjs', + 'test-*.cjs', + 'test/**/*.cjs' ]; defaultApiOptions = { clearLogOnNextRun: false, @@ -141,25 +133,25 @@ group('chokidar', (beforeEach, test, group) => { stdin = new PassThrough(); stdin.pause(); - Subject = proxyWatcher(); + Subject = Watcher; }); - const start = ignoredByWatcher => new Subject({reporter, api, filter: [], globs: normalizeGlobs({files, ignoredByWatcher, extensions: ['js'], providers: []}), projectDir: process.cwd(), providers: []}); + const start = ignoredByWatcher => new Subject({reporter, api, filter: [], globs: normalizeGlobs({files, ignoredByWatcher, extensions: ['cjs'], providers: []}), projectDir: process.cwd(), providers: []}); const emitChokidar = (event, path) => { chokidarEmitter.emit('all', event, path); }; const add = path => { - emitChokidar('add', path || 'source.js'); + emitChokidar('add', path || 'source.cjs'); }; const change = path => { - emitChokidar('change', path || 'source.js'); + emitChokidar('change', path || 'source.cjs'); }; const unlink = path => { - emitChokidar('unlink', path || 'source.js'); + emitChokidar('unlink', path || 'source.cjs'); }; const delay = () => new Promise(resolve => { @@ -195,7 +187,7 @@ group('chokidar', (beforeEach, test, group) => { test('ignored files are configurable', t => { t.plan(2); - const ignoredByWatcher = ['!foo.js', 'bar.js', '!baz.js', 'qux.js']; + const ignoredByWatcher = ['!foo.cjs', 'bar.cjs', '!baz.cjs', 'qux.cjs']; start(ignoredByWatcher); t.ok(chokidar.watch.calledOnce); @@ -203,7 +195,7 @@ group('chokidar', (beforeEach, test, group) => { ['**/*'], { cwd: process.cwd(), - ignored: [...defaultIgnore.map(dir => `${dir}/**/*`), '**/node_modules/**/*', '**/*.snap.md', 'ava.config.js', 'ava.config.cjs', 'bar.js', 'qux.js'], + ignored: [...defaultIgnore.map(dir => `${dir}/**/*`), '**/node_modules/**/*', '**/*.snap.md', 'ava.config.js', 'ava.config.cjs', 'bar.cjs', 'qux.cjs'], ignoreInitial: true } ]); @@ -254,9 +246,9 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); start(); - variant.fire('file.js'); + variant.fire('file.cjs'); t.ok(debug.calledOnce); - t.strictSame(debug.firstCall.args, ['ava:watcher', 'Detected %s of %s', variant.event, 'file.js']); + t.strictSame(debug.firstCall.args, ['ava:watcher', 'Detected %s of %s', variant.event, 'file.cjs']); }); } @@ -467,11 +459,11 @@ group('chokidar', (beforeEach, test, group) => { }; })); - variant.fire('test.js'); + variant.fire('test.cjs'); return debounce().then(() => { t.ok(api.run.calledTwice); // The `test.js` file is provided - t.strictSame(api.run.secondCall.args, [{files: [path.resolve('test.js')], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve('test.cjs')], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -494,12 +486,12 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(Promise.resolve(runStatus)); start(); - add('test-one.js'); - change('test-two.js'); + add('test-one.cjs'); + change('test-two.cjs'); return debounce(2).then(() => { t.ok(api.run.calledTwice); // The test files are provided - t.strictSame(api.run.secondCall.args, [{files: [path.resolve('test-one.js'), path.resolve('test-two.js')], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve('test-one.cjs'), path.resolve('test-two.cjs')], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -512,8 +504,8 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(Promise.resolve(runStatus)); start(); - add('test.js'); - unlink('source.js'); + add('test.cjs'); + unlink('source.cjs'); return debounce(2).then(() => { t.ok(api.run.calledTwice); // No explicit files are provided @@ -530,7 +522,7 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(Promise.resolve(runStatus)); start(); - unlink('test.js'); + unlink('test.cjs'); return debounce().then(() => { t.ok(api.run.calledOnce); }); @@ -539,15 +531,15 @@ group('chokidar', (beforeEach, test, group) => { test('determines whether changed files are tests based on the initial files patterns', t => { t.plan(2); - files = ['foo-{bar,baz}.js']; + files = ['foo-{bar,baz}.cjs']; api.run.returns(Promise.resolve(runStatus)); start(); - add('foo-bar.js'); - add('foo-baz.js'); + add('foo-bar.cjs'); + add('foo-baz.cjs'); return debounce(2).then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.resolve('foo-bar.js'), path.resolve('foo-baz.js')], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve('foo-bar.cjs'), path.resolve('foo-baz.cjs')], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -600,7 +592,7 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(Promise.resolve(runStatus)); start().observeStdin(stdin); - add('test-one.js'); + add('test-one.cjs'); await debounce(); t.ok(api.run.calledTwice); @@ -608,13 +600,13 @@ group('chokidar', (beforeEach, test, group) => { await delay(); t.ok(api.run.calledThrice); - t.strictSame(api.run.thirdCall.args, [{files: [path.resolve('test-one.js')], filter: [], runtimeOptions: {...options, runVector: 3}}]); + t.strictSame(api.run.thirdCall.args, [{files: [path.resolve('test-one.cjs')], filter: [], runtimeOptions: {...options, runVector: 3}}]); stdin.write('\tu \n'); await delay(); t.equal(api.run.callCount, 4); - t.strictSame(api.run.lastCall.args, [{files: [path.resolve('test-one.js')], filter: [], runtimeOptions: {...options, runVector: 4}}]); + t.strictSame(api.run.lastCall.args, [{files: [path.resolve('test-one.cjs')], filter: [], runtimeOptions: {...options, runVector: 4}}]); }); for (const input of ['r', 'rs', 'u']) { @@ -728,7 +720,7 @@ group('chokidar', (beforeEach, test, group) => { api.run.returns(Promise.resolve(runStatus)); start(); - emitChokidar('foo', 'foo.js'); + emitChokidar('foo', 'foo.cjs'); return debounce().then(() => { t.ok(api.run.calledOnce); }); @@ -823,14 +815,14 @@ group('chokidar', (beforeEach, test, group) => { })); const watcher = start(ignoredByWatcher); - const files = [path.join('test', '1.js'), path.join('test', '2.js')]; + const files = [path.join('test', '1.cjs'), path.join('test', '2.cjs')]; const absFiles = files.map(relFile => path.resolve(relFile)); apiEmitter.emit('run', { files: absFiles, status: runStatus }); - emitDependencies(path.resolve(files[0]), [path.resolve('dep-1.js'), path.resolve('dep-3.js')]); - emitDependencies(path.resolve(files[1]), [path.resolve('dep-2.js'), path.resolve('dep-3.js')]); + emitDependencies(path.resolve(files[0]), [path.resolve('dep-1.cjs'), path.resolve('dep-3.cjs')]); + emitDependencies(path.resolve(files[1]), [path.resolve('dep-2.cjs'), path.resolve('dep-3.cjs')]); done(); api.run.returns(new Promise(() => {})); @@ -841,10 +833,10 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - change('dep-1.js'); + change('dep-1.cjs'); return debounce().then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.js'))], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.cjs'))], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -856,7 +848,7 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - change('cannot-be-mapped.js'); + change('cannot-be-mapped.cjs'); return debounce().then(() => { t.ok(api.run.calledTwice); t.strictSame(api.run.secondCall.args, [{files: [], filter: [], runtimeOptions: { @@ -871,12 +863,12 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - change('dep-1.js'); - change(path.join('test', '2.js')); + change('dep-1.cjs'); + change(path.join('test', '2.cjs')); return debounce(2).then(() => { t.ok(api.run.calledTwice); t.strictSame(api.run.secondCall.args, [{ - files: [path.resolve(path.join('test', '2.js')), path.resolve(path.join('test', '1.js'))], + files: [path.resolve(path.join('test', '2.cjs')), path.resolve(path.join('test', '1.cjs'))], filter: [], runtimeOptions: { ...defaultApiOptions, @@ -891,11 +883,11 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - change(path.join('test', '1.js')); - change('dep-1.js'); + change(path.join('test', '1.cjs')); + change('dep-1.cjs'); return debounce(2).then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.js'))], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.cjs'))], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -907,11 +899,11 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - unlink(path.join('test', '1.js')); - change('dep-3.js'); + unlink(path.join('test', '1.cjs')); + change('dep-3.cjs'); return debounce(2).then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '2.js'))], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '2.cjs'))], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -923,11 +915,11 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - emitDependencies(path.resolve(path.join('test', '1.js')), [path.resolve('dep-4.js')]); - change('dep-4.js'); + emitDependencies(path.resolve(path.join('test', '1.cjs')), [path.resolve('dep-4.cjs')]); + change('dep-4.cjs'); return debounce().then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.js'))], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.resolve(path.join('test', '1.cjs'))], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -938,11 +930,11 @@ group('chokidar', (beforeEach, test, group) => { for (const variant of [ { desc: 'does not track ignored dependencies', - ignoredByWatcher: ['dep-2.js'] + ignoredByWatcher: ['dep-2.cjs'] }, { desc: 'exclusion patterns affect tracked source dependencies', - ignoredByWatcher: ['dep-2.js'] + ignoredByWatcher: ['dep-2.cjs'] } ]) { test(variant.desc, t => { @@ -952,7 +944,7 @@ group('chokidar', (beforeEach, test, group) => { // `dep-2.js` isn't treated as a source and therefore it's not tracked as // a dependency for `test/2.js`. Pretend Chokidar detected a change to // verify (normally Chokidar would also be ignoring this file but hey). - change('dep-2.js'); + change('dep-2.cjs'); return debounce().then(() => { t.ok(api.run.calledTwice); // Expect all tests to be rerun since `dep-2.js` is not a tracked @@ -970,16 +962,16 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - emitDependencies(path.join('test', '1.js'), [path.resolve('package.json'), path.resolve('index.js'), path.resolve('lib/util.js')]); - emitDependencies(path.join('test', '2.js'), [path.resolve('foo.bar')]); + emitDependencies(path.join('test', '1.cjs'), [path.resolve('package.json'), path.resolve('index.cjs'), path.resolve('lib/util.cjs')]); + emitDependencies(path.join('test', '2.cjs'), [path.resolve('foo.bar')]); change('package.json'); - change('index.js'); - change(path.join('lib', 'util.js')); + change('index.cjs'); + change(path.join('lib', 'util.cjs')); api.run.returns(Promise.resolve(runStatus)); return debounce(3).then(() => { t.ok(api.run.calledTwice); - t.strictSame(api.run.secondCall.args, [{files: [path.join('test', '1.js')], filter: [], runtimeOptions: { + t.strictSame(api.run.secondCall.args, [{files: [path.join('test', '1.cjs')], filter: [], runtimeOptions: { ...defaultApiOptions, clearLogOnNextRun: true, runVector: 2 @@ -1006,8 +998,8 @@ group('chokidar', (beforeEach, test, group) => { // Ensure `test/1.js` also depends on the excluded files emitDependencies( - path.join('test', '1.js'), - [...excludedFiles.map(relPath => path.resolve(relPath)), 'dep-1.js'] + path.join('test', '1.cjs'), + [...excludedFiles.map(relPath => path.resolve(relPath)), 'dep-1.cjs'] ); // Modify all excluded files @@ -1031,10 +1023,10 @@ group('chokidar', (beforeEach, test, group) => { t.plan(2); seed(); - change('dep-1.js'); + change('dep-1.cjs'); return debounce().then(() => { t.ok(debug.calledTwice); - t.strictSame(debug.secondCall.args, ['ava:watcher', '%s is a dependency of %s', path.resolve('dep-1.js'), path.resolve(path.join('test', '1.js'))]); + t.strictSame(debug.secondCall.args, ['ava:watcher', '%s is a dependency of %s', path.resolve('dep-1.cjs'), path.resolve(path.join('test', '1.cjs'))]); }); }); @@ -1042,10 +1034,10 @@ group('chokidar', (beforeEach, test, group) => { t.plan(3); seed(); - change('cannot-be-mapped.js'); + change('cannot-be-mapped.cjs'); return debounce().then(() => { t.ok(debug.calledThrice); - t.strictSame(debug.secondCall.args, ['ava:watcher', 'Files remain that cannot be traced to specific tests: %O', [path.resolve('cannot-be-mapped.js')]]); + t.strictSame(debug.secondCall.args, ['ava:watcher', 'Files remain that cannot be traced to specific tests: %O', [path.resolve('cannot-be-mapped.cjs')]]); t.strictSame(debug.thirdCall.args, ['ava:watcher', 'Rerunning all tests']); }); }); @@ -1088,7 +1080,7 @@ group('chokidar', (beforeEach, test, group) => { }; }); - const t1 = path.join('test', '1.js'); + const t1 = path.join('test', '1.cjs'); const t1Absolute = path.resolve(t1); const seed = () => { @@ -1187,10 +1179,10 @@ group('chokidar', (beforeEach, test, group) => { runStatusEmitter.emit('stateChange', {type: 'worker-finished', testFile}); }; - const t1 = path.join('test', '1.js'); - const t2 = path.join('test', '2.js'); - const t3 = path.join('test', '3.js'); - const t4 = path.join('test', '4.js'); + const t1 = path.join('test', '1.cjs'); + const t2 = path.join('test', '2.cjs'); + const t3 = path.join('test', '3.cjs'); + const t4 = path.join('test', '4.cjs'); const t1Absolute = path.resolve(t1); const t2Absolute = path.resolve(t2); const t3Absolute = path.resolve(t3); @@ -1353,8 +1345,8 @@ group('chokidar', (beforeEach, test, group) => { })); const watcher = start(); - const files = [path.join('test', '1.js'), path.join('test', '2.js')]; - const filesAbsolute = [path.join('test', '1.js'), path.join('test', '2.js')].map(file => path.resolve(file)); + const files = [path.join('test', '1.cjs'), path.join('test', '2.cjs')]; + const filesAbsolute = [path.join('test', '1.cjs'), path.join('test', '2.cjs')].map(file => path.resolve(file)); apiEmitter.emit('run', { files, status: runStatus diff --git a/test/README.md b/test/README.md index 4e35d7e8e..38e82ef84 100644 --- a/test/README.md +++ b/test/README.md @@ -2,6 +2,6 @@ This directory contains tests that are run using a stable version of AVA. You can run them using `npx test-ava`. -Tests should be placed in their own directory, grouped by area of responsibility. Use the `exec.fixture()` helper to launch the AVA version that is in the repository to run tests. Place these in a nested `fixtures` directory. Add a relative dependency in `package.json`. You can then import from `ava`. +Tests should be placed in their own directory, grouped by area of responsibility. Use the `exec` helper to launch the AVA version that is in the repository to run tests. Place these in a nested `fixtures` directory. Add a relative dependency in `package.json`. You can then import from `ava`. Prefer snapshotting the test results. diff --git a/test/assertions/fixtures/happy-path.js b/test/assertions/fixtures/happy-path.js index 6047ac9aa..f9f5f07ad 100644 --- a/test/assertions/fixtures/happy-path.js +++ b/test/assertions/fixtures/happy-path.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; const passes = async (t, assertion, ...args) => { await t[assertion](...args); diff --git a/test/assertions/fixtures/package.json b/test/assertions/fixtures/package.json index f9b9cb835..54f672450 100644 --- a/test/assertions/fixtures/package.json +++ b/test/assertions/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "files": [ - "*.js" - ] - } + "type": "module", + "ava": { + "files": [ + "*.js" + ] + } } diff --git a/test/assertions/test.js b/test/assertions/test.js index 426d7a67e..fc3262d0d 100644 --- a/test/assertions/test.js +++ b/test/assertions/test.js @@ -1,7 +1,8 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('happy path', async t => { - const result = await exec.fixture(['happy-path.js']); + const result = await fixture(['happy-path.js']); t.snapshot(result.stats.passed.map(({title}) => title)); }); diff --git a/test/builtin-nodejs-assert/fixtures/assert-failure.js b/test/builtin-nodejs-assert/fixtures/assert-failure.js index a7e0562bf..e42004a7a 100644 --- a/test/builtin-nodejs-assert/fixtures/assert-failure.js +++ b/test/builtin-nodejs-assert/fixtures/assert-failure.js @@ -1,5 +1,6 @@ -const test = require('ava'); -const assert = require('assert'); +import assert from 'assert'; + +import test from 'ava'; test('test', () => { assert(false); diff --git a/test/builtin-nodejs-assert/fixtures/package.json b/test/builtin-nodejs-assert/fixtures/package.json index f9b9cb835..54f672450 100644 --- a/test/builtin-nodejs-assert/fixtures/package.json +++ b/test/builtin-nodejs-assert/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "files": [ - "*.js" - ] - } + "type": "module", + "ava": { + "files": [ + "*.js" + ] + } } diff --git a/test/builtin-nodejs-assert/test.js b/test/builtin-nodejs-assert/test.js index c18c34468..3e1547f58 100644 --- a/test/builtin-nodejs-assert/test.js +++ b/test/builtin-nodejs-assert/test.js @@ -1,5 +1,6 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('node assertion failures are reported to the console when running in a terminal', async t => { const options = { @@ -11,14 +12,14 @@ test('node assertion failures are reported to the console when running in a term } }; - const result = await t.throwsAsync(exec.fixture(['assert-failure.js'], options)); + const result = await t.throwsAsync(fixture(['assert-failure.js'], options)); const error = result.stats.getError(result.stats.failed[0]); t.true(error.values.every(value => value.formatted.includes('AssertionError'))); }); test('node assertion failures are reported to the console when not running in a terminal', async t => { - const result = await t.throwsAsync(exec.fixture(['assert-failure.js'])); + const result = await t.throwsAsync(fixture(['assert-failure.js'])); const error = result.stats.getError(result.stats.failed[0]); t.true(error.values.every(value => value.formatted.includes('AssertionError'))); diff --git a/test/concurrency/fixtures/concurrency.js b/test/concurrency/fixtures/concurrency.js index d4747061d..c76eefb11 100644 --- a/test/concurrency/fixtures/concurrency.js +++ b/test/concurrency/fixtures/concurrency.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('works', t => { t.pass(); diff --git a/test/concurrency/fixtures/package.json b/test/concurrency/fixtures/package.json index a0befd106..54f672450 100644 --- a/test/concurrency/fixtures/package.json +++ b/test/concurrency/fixtures/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "files": [ "*.js" diff --git a/test/concurrency/test.js b/test/concurrency/test.js index 9d591c9d6..eb0007830 100644 --- a/test/concurrency/test.js +++ b/test/concurrency/test.js @@ -1,30 +1,31 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, fixture} from '../helpers/exec.js'; test('bails when --concurrency is provided without value', async t => { - const result = await t.throwsAsync(exec.fixture(['--concurrency', 'concurrency.js'])); + const result = await t.throwsAsync(fixture(['--concurrency', 'concurrency.js'])); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('bails when --concurrency is provided with an input that is a string', async t => { - const result = await t.throwsAsync(exec.fixture(['--concurrency=foo', 'concurrency.js'])); + const result = await t.throwsAsync(fixture(['--concurrency=foo', 'concurrency.js'])); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('bails when --concurrency is provided with an input that is a float', async t => { - const result = await t.throwsAsync(exec.fixture(['--concurrency=4.7', 'concurrency.js'])); + const result = await t.throwsAsync(fixture(['--concurrency=4.7', 'concurrency.js'])); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('bails when --concurrency is provided with an input that is negative', async t => { - const result = await t.throwsAsync(exec.fixture(['--concurrency=-1', 'concurrency.js'])); + const result = await t.throwsAsync(fixture(['--concurrency=-1', 'concurrency.js'])); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('works when --concurrency is provided with a value', async t => { - await t.notThrowsAsync(exec.fixture(['--concurrency=1', 'concurrency.js'])); + await t.notThrowsAsync(fixture(['--concurrency=1', 'concurrency.js'])); }); diff --git a/test/config/fixtures/config-errors/package.json b/test/config/fixtures/config-errors/package.json index 0967ef424..bedb411a9 100644 --- a/test/config/fixtures/config-errors/package.json +++ b/test/config/fixtures/config-errors/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/config/fixtures/config-errors/test.js b/test/config/fixtures/config-errors/test.js index 5ca41efa1..5950a2850 100644 --- a/test/config/fixtures/config-errors/test.js +++ b/test/config/fixtures/config-errors/test.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/factory-promise-return/ava.config.js b/test/config/fixtures/factory-promise-return/ava.config.js index 039868ff6..6049bca12 100644 --- a/test/config/fixtures/factory-promise-return/ava.config.js +++ b/test/config/fixtures/factory-promise-return/ava.config.js @@ -1,4 +1,4 @@ -module.exports = async () => { +export default async () => { return { failFast: true }; diff --git a/test/config/fixtures/factory-promise-return/package.json b/test/config/fixtures/factory-promise-return/package.json index 0967ef424..bedb411a9 100644 --- a/test/config/fixtures/factory-promise-return/package.json +++ b/test/config/fixtures/factory-promise-return/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js b/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js index 159662d3d..e60d0fef4 100644 --- a/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js +++ b/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ava/no-ignored-test-files -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js b/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js index 159662d3d..e60d0fef4 100644 --- a/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js +++ b/test/config/fixtures/mjs-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ava/no-ignored-test-files -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-1.js b/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-1.js index 5ca41efa1..5950a2850 100644 --- a/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-1.js +++ b/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-1.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-2.js b/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-2.js index 5ca41efa1..5950a2850 100644 --- a/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-2.js +++ b/test/config/fixtures/mjs-with-tests/dir-a/dir-a-base-2.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/mjs-with-tests/package.json b/test/config/fixtures/mjs-with-tests/package.json index 9992cb44e..dc02217a3 100644 --- a/test/config/fixtures/mjs-with-tests/package.json +++ b/test/config/fixtures/mjs-with-tests/package.json @@ -1,4 +1,5 @@ { + "type": "module", "name": "application-name", "version": "0.0.1" } diff --git a/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js b/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js index 159662d3d..e60d0fef4 100644 --- a/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js +++ b/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-3.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ava/no-ignored-test-files -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js b/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js index 159662d3d..e60d0fef4 100644 --- a/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js +++ b/test/config/fixtures/pkg-with-tests/dir-a-wrapper/dir-a/dir-a-wrapper-4.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ava/no-ignored-test-files -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-1.js b/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-1.js index 5ca41efa1..5950a2850 100644 --- a/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-1.js +++ b/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-1.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-2.js b/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-2.js index 5ca41efa1..5950a2850 100644 --- a/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-2.js +++ b/test/config/fixtures/pkg-with-tests/dir-a/dir-a-base-2.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('test', t => { t.pass(); diff --git a/test/config/fixtures/pkg-with-tests/package.json b/test/config/fixtures/pkg-with-tests/package.json index a1c131239..b7eb07875 100644 --- a/test/config/fixtures/pkg-with-tests/package.json +++ b/test/config/fixtures/pkg-with-tests/package.json @@ -1,7 +1,10 @@ { + "type": "module", "name": "application-name", "version": "0.0.1", "ava": { - "files": ["dir-a/*.js"] + "files": [ + "dir-a/*.js" + ] } } diff --git a/test/config/fixtures/promise-config/ava.config.js b/test/config/fixtures/promise-config/ava.config.js index 351781036..978735ddf 100644 --- a/test/config/fixtures/promise-config/ava.config.js +++ b/test/config/fixtures/promise-config/ava.config.js @@ -1,3 +1,3 @@ -module.exports = Promise.resolve({ +export default Promise.resolve({ failFast: true }); diff --git a/test/config/fixtures/promise-config/package.json b/test/config/fixtures/promise-config/package.json index 0967ef424..bedb411a9 100644 --- a/test/config/fixtures/promise-config/package.json +++ b/test/config/fixtures/promise-config/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/config/integration.js b/test/config/integration.js index 4b746fb4f..fc3be3eb8 100644 --- a/test/config/integration.js +++ b/test/config/integration.js @@ -1,15 +1,17 @@ -const fs = require('fs'); -const path = require('path'); -const tempy = require('tempy'); -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import fs from 'fs'; +import path from 'path'; + +import test from '@ava/test'; +import tempy from 'tempy'; + +import {cwd, fixture} from '../helpers/exec.js'; test('formats errors from ava.config.js', async t => { const options = { - cwd: exec.cwd('config-errors') + cwd: cwd('config-errors') }; - const result = await t.throwsAsync(exec.fixture(['test.js'], options)); + const result = await t.throwsAsync(fixture(['test.js'], options)); const lines = result.stderr.split('\n'); while (lines.length > 1 && lines[0] !== '') { // Strip VS Code debugger prefixes. @@ -23,30 +25,30 @@ test('formats errors from ava.config.js', async t => { test('works as expected when run from the package.json directory', async t => { const options = { - cwd: exec.cwd('pkg-with-tests') + cwd: cwd('pkg-with-tests') }; - const result = await exec.fixture([], options); + const result = await fixture([], options); t.snapshot(result.stats.passed, 'resolves test files from configuration'); }); test('resolves tests from the package.json dir if none are specified on cli', async t => { const options = { - cwd: exec.cwd('pkg-with-tests/dir-a-wrapper') + cwd: cwd('pkg-with-tests/dir-a-wrapper') }; - const result = await exec.fixture(['--verbose'], options); + const result = await fixture(['--verbose'], options); t.snapshot(result.stats.passed, 'resolves test files from configuration'); }); test('resolves tests from an .mjs config file', async t => { const options = { - cwd: exec.cwd('mjs-with-tests/dir-a-wrapper') + cwd: cwd('mjs-with-tests/dir-a-wrapper') }; - const result = await exec.fixture(['--verbose'], options); + const result = await fixture(['--verbose'], options); t.snapshot(result.stats.passed, 'resolves test files from configuration'); }); @@ -61,7 +63,7 @@ test('use current working directory if `package.json` is not found', async t => cwd }; - const result = await exec.fixture([], options); + const result = await fixture([], options); t.snapshot(result.stats.passed, 'resolves test files without configuration'); }); diff --git a/test/config/loader.js b/test/config/loader.js index 9d6c86603..d462e0797 100644 --- a/test/config/loader.js +++ b/test/config/loader.js @@ -1,9 +1,12 @@ -const path = require('path'); -const test = require('@ava/test'); -const {loadConfig} = require('../../lib/load-config'); +import path from 'path'; +import {fileURLToPath} from 'url'; + +import test from '@ava/test'; + +import {loadConfig} from '../../lib/load-config.js'; const CWD = process.cwd(); -const FIXTURE_ROOT = path.resolve(__dirname, '../../test-tap/fixture/load-config'); +const FIXTURE_ROOT = fileURLToPath(new URL('../../test-tap/fixture/load-config', import.meta.url)); const resolve = relpath => path.resolve(FIXTURE_ROOT, relpath); diff --git a/test/config/next-gen.js b/test/config/next-gen.js index b1d49987c..241ca2c7f 100644 --- a/test/config/next-gen.js +++ b/test/config/next-gen.js @@ -1,9 +1,12 @@ -const path = require('path'); -const test = require('@ava/test'); -const {loadConfig} = require('../../lib/load-config'); +import path from 'path'; +import {fileURLToPath} from 'url'; + +import test from '@ava/test'; + +import {loadConfig} from '../../lib/load-config.js'; const CWD = process.cwd(); -const FIXTURE_ROOT = path.resolve(__dirname, 'fixtures'); +const FIXTURE_ROOT = fileURLToPath(new URL('fixtures', import.meta.url)); const resolve = relpath => path.resolve(FIXTURE_ROOT, relpath); diff --git a/test/configurable-module-format/commonjs.js b/test/configurable-module-format/commonjs.js index 5f8ed8f81..52dd43a6a 100644 --- a/test/configurable-module-format/commonjs.js +++ b/test/configurable-module-format/commonjs.js @@ -1,8 +1,9 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('load js and cjs (default configuration)', async t => { - const result = await exec.fixture(['*.js', '*.cjs']); + const result = await fixture(['*.js', '*.cjs']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 2); t.true(files.has('test.cjs')); @@ -10,7 +11,7 @@ test('load js and cjs (default configuration)', async t => { }); test('load js and cjs (using an extensions array)', async t => { - const result = await exec.fixture(['*.js', '*.cjs', '--config', 'array-extensions.config.js']); + const result = await fixture(['*.js', '*.cjs', '--config', 'array-extensions.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 2); t.true(files.has('test.cjs')); @@ -18,7 +19,7 @@ test('load js and cjs (using an extensions array)', async t => { }); test('load js and cjs (using an extensions object)', async t => { - const result = await exec.fixture(['*.js', '*.cjs', '--config', 'object-extensions.config.js']); + const result = await fixture(['*.js', '*.cjs', '--config', 'object-extensions.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 2); t.true(files.has('test.cjs')); diff --git a/test/configurable-module-format/custom.js b/test/configurable-module-format/custom.js index 3f5d6c3e4..9c6f461c1 100644 --- a/test/configurable-module-format/custom.js +++ b/test/configurable-module-format/custom.js @@ -1,15 +1,16 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('load ts as commonjs (using an extensions array)', async t => { - const result = await exec.fixture(['*.ts', '--config', 'array-custom.config.js']); + const result = await fixture(['*.ts', '--config', 'array-custom.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 1); t.true(files.has('test.ts')); }); test('load ts as commonjs (using an extensions object)', async t => { - const result = await exec.fixture(['*.ts', '--config', 'object-custom.config.js']); + const result = await fixture(['*.ts', '--config', 'object-custom.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 1); t.true(files.has('test.ts')); diff --git a/test/configurable-module-format/fixtures/test.ts b/test/configurable-module-format/fixtures/test.ts index 93d621261..9be2f604f 100644 --- a/test/configurable-module-format/fixtures/test.ts +++ b/test/configurable-module-format/fixtures/test.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line ava/no-ignored-test-files -const test = require('ava'); +const test = require('ava'); // eslint-disable-line @typescript-eslint/no-var-requires, ava/no-ignored-test-files test('always passing test', t => { const numberWithTypes = 0; diff --git a/test/configurable-module-format/invalid-configurations.js b/test/configurable-module-format/invalid-configurations.js index 1df36e353..8b543caeb 100644 --- a/test/configurable-module-format/invalid-configurations.js +++ b/test/configurable-module-format/invalid-configurations.js @@ -1,22 +1,23 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, fixture} from '../helpers/exec.js'; test('cannot configure how js extensions should be loaded', async t => { - const result = await t.throwsAsync(exec.fixture(['--config', 'change-js-loading.config.js'])); - t.snapshot(exec.cleanOutput(result.stderr)); + const result = await t.throwsAsync(fixture(['--config', 'change-js-loading.config.js'])); + t.snapshot(cleanOutput(result.stderr)); }); test('cannot configure how cjs extensions should be loaded', async t => { - const result = await t.throwsAsync(exec.fixture(['--config', 'change-cjs-loading.config.js'])); - t.snapshot(exec.cleanOutput(result.stderr)); + const result = await t.throwsAsync(fixture(['--config', 'change-cjs-loading.config.js'])); + t.snapshot(cleanOutput(result.stderr)); }); test('cannot configure how mjs extensions should be loaded', async t => { - const result = await t.throwsAsync(exec.fixture(['--config', 'change-mjs-loading.config.js'])); - t.snapshot(exec.cleanOutput(result.stderr)); + const result = await t.throwsAsync(fixture(['--config', 'change-mjs-loading.config.js'])); + t.snapshot(cleanOutput(result.stderr)); }); test('custom extensions must be either commonjs or module', async t => { - const result = await t.throwsAsync(exec.fixture(['--config', 'bad-custom-type.config.js'])); - t.snapshot(exec.cleanOutput(result.stderr)); + const result = await t.throwsAsync(fixture(['--config', 'bad-custom-type.config.js'])); + t.snapshot(cleanOutput(result.stderr)); }); diff --git a/test/configurable-module-format/module.js b/test/configurable-module-format/module.js index 9b07beb08..110c57d23 100644 --- a/test/configurable-module-format/module.js +++ b/test/configurable-module-format/module.js @@ -1,22 +1,23 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('load mjs as module (default configuration)', async t => { - const result = await exec.fixture(['*.mjs']); + const result = await fixture(['*.mjs']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 1); t.true(files.has('test.mjs')); }); test('load mjs as module (using an extensions array)', async t => { - const result = await exec.fixture(['*.mjs', '--config', 'array-extensions.config.js']); + const result = await fixture(['*.mjs', '--config', 'array-extensions.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 1); t.true(files.has('test.mjs')); }); test('load mjs as module (using an extensions object)', async t => { - const result = await exec.fixture(['*.mjs', '--config', 'object-extensions.config.js']); + const result = await fixture(['*.mjs', '--config', 'object-extensions.config.js']); const files = new Set(result.stats.passed.map(({file}) => file)); t.is(files.size, 1); t.true(files.has('test.mjs')); diff --git a/test/environment-variables/fixtures/invalid-environment-variables/package.json b/test/environment-variables/fixtures/invalid-environment-variables/package.json index be0d922a7..71e974fed 100644 --- a/test/environment-variables/fixtures/invalid-environment-variables/package.json +++ b/test/environment-variables/fixtures/invalid-environment-variables/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "environmentVariables": { "SOME_INVALID_ENVIRONMENT_VARIABLE": {} diff --git a/test/environment-variables/test.js b/test/environment-variables/test.js index 0cb91f851..62c33db7a 100644 --- a/test/environment-variables/test.js +++ b/test/environment-variables/test.js @@ -1,35 +1,36 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, cwd, fixture} from '../helpers/exec.js'; test('sets default environment variables from the config', async t => { const options = { - cwd: exec.cwd('environment-variables') + cwd: cwd('environment-variables') }; - const results = await exec.fixture(['environment-variables.js'], options); + const results = await fixture(['environment-variables.js'], options); t.snapshot(results.stats.passed, 'tests pass'); }); test('overrides environment variables provided through the CLI', async t => { const options = { - cwd: exec.cwd('environment-variables'), + cwd: cwd('environment-variables'), env: { MY_ENVIRONMENT_VARIABLE: 'some value (updated)' } }; - const results = await exec.fixture(['environment-variables.js'], options); + const results = await fixture(['environment-variables.js'], options); t.snapshot(results.stats.passed, 'tests pass'); }); test('errors if environment variables are not string values', async t => { const options = { - cwd: exec.cwd('invalid-environment-variables') + cwd: cwd('invalid-environment-variables') }; - const result = await t.throwsAsync(exec.fixture(['environment-variables.js'], options)); + const result = await t.throwsAsync(fixture(['environment-variables.js'], options)); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); diff --git a/test/extensions/fixtures/shared-duplicates/package.json b/test/extensions/fixtures/shared-duplicates/package.json index 8c50a1e05..13822a8ec 100644 --- a/test/extensions/fixtures/shared-duplicates/package.json +++ b/test/extensions/fixtures/shared-duplicates/package.json @@ -1,8 +1,14 @@ { + "type": "module", "ava": { "babel": { - "extensions": ["js", "jsx"] + "extensions": [ + "js", + "jsx" + ] }, - "extensions": ["jsx"] + "extensions": [ + "jsx" + ] } } diff --git a/test/extensions/fixtures/top-level-duplicates/package.json b/test/extensions/fixtures/top-level-duplicates/package.json index faee1de78..c91ca6072 100644 --- a/test/extensions/fixtures/top-level-duplicates/package.json +++ b/test/extensions/fixtures/top-level-duplicates/package.json @@ -1,5 +1,11 @@ { + "type": "module", "ava": { - "extensions": ["js", "js", "jsx", "jsx"] + "extensions": [ + "js", + "js", + "jsx", + "jsx" + ] } } diff --git a/test/extensions/fixtures/top-level/package.json b/test/extensions/fixtures/top-level/package.json index 9e75c7302..beb2ae334 100644 --- a/test/extensions/fixtures/top-level/package.json +++ b/test/extensions/fixtures/top-level/package.json @@ -1,5 +1,8 @@ { + "type": "module", "ava": { - "extensions": ["js"] + "extensions": [ + "js" + ] } } diff --git a/test/extensions/test.js b/test/extensions/test.js index 1a908d98e..557046bf7 100644 --- a/test/extensions/test.js +++ b/test/extensions/test.js @@ -1,5 +1,6 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, cwd, fixture} from '../helpers/exec.js'; for (const [where, which] of [ ['top-level', 'top-level-duplicates'], @@ -7,11 +8,11 @@ for (const [where, which] of [ ]) { test(`errors if ${where} extensions include duplicates`, async t => { const options = { - cwd: exec.cwd(which) + cwd: cwd(which) }; - const result = await t.throwsAsync(exec.fixture([], options)); + const result = await t.throwsAsync(fixture([], options)); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); } diff --git a/test/globs/fixtures/files/package.json b/test/globs/fixtures/files/package.json index eaa79f1ff..0ee09c331 100644 --- a/test/globs/fixtures/files/package.json +++ b/test/globs/fixtures/files/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "files": [] } diff --git a/test/globs/fixtures/ignored-by-watcher/package.json b/test/globs/fixtures/ignored-by-watcher/package.json index d14589acf..eb6f557ce 100644 --- a/test/globs/fixtures/ignored-by-watcher/package.json +++ b/test/globs/fixtures/ignored-by-watcher/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "ignoredByWatcher": [] } diff --git a/test/globs/test.js b/test/globs/test.js index 229f97e5b..7b14f7e8d 100644 --- a/test/globs/test.js +++ b/test/globs/test.js @@ -1,22 +1,23 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, cwd, fixture} from '../helpers/exec.js'; test('errors if top-level files is an empty array', async t => { const options = { - cwd: exec.cwd('files') + cwd: cwd('files') }; - const result = await t.throwsAsync(exec.fixture([], options)); + const result = await t.throwsAsync(fixture([], options)); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('errors if top-level ignoredByWatcher is an empty array', async t => { const options = { - cwd: exec.cwd('ignored-by-watcher') + cwd: cwd('ignored-by-watcher') }; - const result = await t.throwsAsync(exec.fixture([], options)); + const result = await t.throwsAsync(fixture([], options)); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); diff --git a/test/helpers/exec.js b/test/helpers/exec.js index 1dc22780c..9c7e41001 100644 --- a/test/helpers/exec.js +++ b/test/helpers/exec.js @@ -1,12 +1,13 @@ -const path = require('path'); +import path from 'path'; +import {fileURLToPath} from 'url'; -const test = require('@ava/test'); -const execa = require('execa'); -const defaultsDeep = require('lodash/defaultsDeep'); -const replaceString = require('replace-string'); +import test from '@ava/test'; +import execa from 'execa'; +import defaultsDeep from 'lodash/defaultsDeep.js'; +import replaceString from 'replace-string'; -const cliPath = path.resolve(__dirname, '../../entrypoints/cli.mjs'); -const ttySimulator = path.join(__dirname, './simulate-tty.js'); +const cliPath = fileURLToPath(new URL('../../entrypoints/cli.mjs', import.meta.url)); +const ttySimulator = fileURLToPath(new URL('simulate-tty.cjs', import.meta.url)); const TEST_AVA_IMPORT_FROM = path.join(process.cwd(), 'entrypoints/main.cjs'); @@ -29,8 +30,8 @@ const compareStatObjects = (a, b) => { return 1; }; -exports.cwd = (...paths) => path.join(path.dirname(test.meta.file), 'fixtures', ...paths); -exports.cleanOutput = string => string.replace(/^\W+/, '').replace(/\W+\n+$/g, '').trim(); +export const cwd = (...paths) => path.join(path.dirname(test.meta.file), 'fixtures', ...paths); +export const cleanOutput = string => string.replace(/^\W+/, '').replace(/\W+\n+$/g, '').trim(); const NO_FORWARD_PREFIX = Buffer.from('🤗', 'utf8'); @@ -42,14 +43,14 @@ const forwardErrorOutput = async from => { } }; -exports.fixture = async (args, options = {}) => { - const cwd = options.cwd || exports.cwd(); +export const fixture = async (args, options = {}) => { + const workingDir = options.cwd || cwd(); const running = execa.node(cliPath, args, defaultsDeep({ env: { AVA_EMIT_RUN_STATUS_OVER_IPC: 'I\'ll find a payphone baby / Take some time to talk to you', TEST_AVA_IMPORT_FROM }, - cwd, + cwd: workingDir, serialization: 'advanced', nodeOptions: ['--require', ttySimulator] }, options)); @@ -83,7 +84,7 @@ exports.fixture = async (args, options = {}) => { switch (statusEvent.type) { case 'hook-failed': { const {title, testFile} = statusEvent; - const statObject = {title, file: normalizePath(cwd, testFile)}; + const statObject = {title, file: normalizePath(workingDir, testFile)}; errors.set(statObject, statusEvent.err); stats.failedHooks.push(statObject); break; @@ -92,12 +93,12 @@ exports.fixture = async (args, options = {}) => { case 'selected-test': { if (statusEvent.skip) { const {title, testFile} = statusEvent; - stats.skipped.push({title, file: normalizePath(cwd, testFile)}); + stats.skipped.push({title, file: normalizePath(workingDir, testFile)}); } if (statusEvent.todo) { const {title, testFile} = statusEvent; - stats.todo.push({title, file: normalizePath(cwd, testFile)}); + stats.todo.push({title, file: normalizePath(workingDir, testFile)}); } break; @@ -111,7 +112,7 @@ exports.fixture = async (args, options = {}) => { case 'test-passed': { const {title, testFile} = statusEvent; - const statObject = {title, file: normalizePath(cwd, testFile)}; + const statObject = {title, file: normalizePath(workingDir, testFile)}; stats.passed.push(statObject); logs.set(statObject, statusEvent.logs); break; @@ -119,7 +120,7 @@ exports.fixture = async (args, options = {}) => { case 'test-failed': { const {title, testFile} = statusEvent; - const statObject = {title, file: normalizePath(cwd, testFile)}; + const statObject = {title, file: normalizePath(workingDir, testFile)}; errors.set(statObject, statusEvent.err); stats.failed.push(statObject); logs.set(statObject, statusEvent.logs); diff --git a/test/helpers/simulate-tty.js b/test/helpers/simulate-tty.cjs similarity index 99% rename from test/helpers/simulate-tty.js rename to test/helpers/simulate-tty.cjs index 59f674518..11f305f05 100644 --- a/test/helpers/simulate-tty.js +++ b/test/helpers/simulate-tty.cjs @@ -1,3 +1,4 @@ +'use strict'; const tty = require('tty'); // Call original method to ensure the correct errors are thrown. diff --git a/test/helpers/with-temporary-fixture.js b/test/helpers/with-temporary-fixture.js index f872866e6..ee2ec4443 100644 --- a/test/helpers/with-temporary-fixture.js +++ b/test/helpers/with-temporary-fixture.js @@ -1,7 +1,7 @@ -const tempy = require('tempy'); -const fse = require('fs-extra'); +import fse from 'fs-extra'; +import tempy from 'tempy'; -async function withTemporaryFixture(cwd, task) { +export async function withTemporaryFixture(cwd, task) { let result; await tempy.directory.task(async temporary => { await fse.copy(cwd, temporary); @@ -10,5 +10,3 @@ async function withTemporaryFixture(cwd, task) { return result; } - -module.exports.withTemporaryFixture = withTemporaryFixture; diff --git a/test/hook-restrictions/fixtures/invalid-snapshots-in-hooks.js b/test/hook-restrictions/fixtures/invalid-snapshots-in-hooks.js index 05432c663..9b7810598 100644 --- a/test/hook-restrictions/fixtures/invalid-snapshots-in-hooks.js +++ b/test/hook-restrictions/fixtures/invalid-snapshots-in-hooks.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test.before(t => { t.snapshot({}); diff --git a/test/hook-restrictions/fixtures/invalid-t-try-in-hooks.js b/test/hook-restrictions/fixtures/invalid-t-try-in-hooks.js index b5daaabaf..21a2b908f 100644 --- a/test/hook-restrictions/fixtures/invalid-t-try-in-hooks.js +++ b/test/hook-restrictions/fixtures/invalid-t-try-in-hooks.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test.before(async t => { await t.try(tt => tt.pass()); diff --git a/test/hook-restrictions/fixtures/package.json b/test/hook-restrictions/fixtures/package.json index a0befd106..54f672450 100644 --- a/test/hook-restrictions/fixtures/package.json +++ b/test/hook-restrictions/fixtures/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "files": [ "*.js" diff --git a/test/hook-restrictions/test.js b/test/hook-restrictions/test.js index 7601c238a..585e16686 100644 --- a/test/hook-restrictions/test.js +++ b/test/hook-restrictions/test.js @@ -1,14 +1,15 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('snapshots cannot be used in hooks', async t => { - const result = await t.throwsAsync(exec.fixture(['invalid-snapshots-in-hooks.js'])); + const result = await t.throwsAsync(fixture(['invalid-snapshots-in-hooks.js'])); const error = result.stats.getError(result.stats.failedHooks[0]); t.snapshot(error.message, 'error message'); }); test('`t.try()` cannot be used in hooks', async t => { - const result = await t.throwsAsync(exec.fixture(['invalid-t-try-in-hooks.js'])); + const result = await t.throwsAsync(fixture(['invalid-t-try-in-hooks.js'])); const error = result.stats.getError(result.stats.failedHooks[0]); t.snapshot(error.message, 'error message'); }); diff --git a/test/line-numbers/fixtures/line-numbers.js b/test/line-numbers/fixtures/line-numbers.js index cc165dec7..45532e7c8 100644 --- a/test/line-numbers/fixtures/line-numbers.js +++ b/test/line-numbers/fixtures/line-numbers.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('unicorn', t => { t.pass(); diff --git a/test/line-numbers/fixtures/package.json b/test/line-numbers/fixtures/package.json index a0befd106..54f672450 100644 --- a/test/line-numbers/fixtures/package.json +++ b/test/line-numbers/fixtures/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "files": [ "*.js" diff --git a/test/line-numbers/test.js b/test/line-numbers/test.js index 55fdbf93d..a1fc13b52 100644 --- a/test/line-numbers/test.js +++ b/test/line-numbers/test.js @@ -1,61 +1,62 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, fixture} from '../helpers/exec.js'; test('select test by line number', async t => { - const result = await exec.fixture(['line-numbers.js', 'line-numbers.js:3']); + const result = await fixture(['line-numbers.js', 'line-numbers.js:3']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); }); test('select serial test by line number', async t => { - const result = await exec.fixture(['line-numbers.js:11']); + const result = await fixture(['line-numbers.js:11']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); }); test('select todo test by line number', async t => { - const result = await exec.fixture(['line-numbers.js:15']); + const result = await fixture(['line-numbers.js:15']); t.snapshot(result.stats.todo, 'selected todo test passes'); }); test('select tests by line number range', async t => { - const result = await exec.fixture(['line-numbers.js:5-7']); + const result = await fixture(['line-numbers.js:5-7']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); }); test('select two tests declared on same line', async t => { - const result = await exec.fixture(['line-numbers.js:18']); + const result = await fixture(['line-numbers.js:18']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); }); test('select only one of two tests declared on same line', async t => { - const result = await exec.fixture(['line-numbers.js:19']); + const result = await fixture(['line-numbers.js:19']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); }); test('no test selected by line number', async t => { - const result = await t.throwsAsync(exec.fixture(['line-numbers.js:6'])); + const result = await t.throwsAsync(fixture(['line-numbers.js:6'])); - t.snapshot(exec.cleanOutput(result.stdout), 'fails with message'); + t.snapshot(cleanOutput(result.stdout), 'fails with message'); }); test('parent call is not selected', async t => { - const result = await t.throwsAsync(exec.fixture(['line-numbers.js:23'])); + const result = await t.throwsAsync(fixture(['line-numbers.js:23'])); - t.snapshot(exec.cleanOutput(result.stdout), 'fails with message'); + t.snapshot(cleanOutput(result.stdout), 'fails with message'); }); test('nested call is selected', async t => { - const result = await exec.fixture(['line-numbers.js:24']); + const result = await fixture(['line-numbers.js:24']); t.snapshot(result.stats.todo, 'no todo tests are selected'); t.snapshot(result.stats.passed, 'selected tests pass'); diff --git a/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js b/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js index 61a4c5feb..d5d9f81b4 100644 --- a/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js +++ b/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('works', t => { t.plan(2); diff --git a/test/node-arguments/fixtures/node-arguments-from-config/package.json b/test/node-arguments/fixtures/node-arguments-from-config/package.json index 83d37be0f..848d376fd 100644 --- a/test/node-arguments/fixtures/node-arguments-from-config/package.json +++ b/test/node-arguments/fixtures/node-arguments-from-config/package.json @@ -1,11 +1,12 @@ { + "type": "module", "ava": { "files": [ "*.js" ], "nodeArguments": [ "--require", - "./setup.js" + "./setup.cjs" ] } } diff --git a/test/node-arguments/fixtures/node-arguments-from-config/setup.js b/test/node-arguments/fixtures/node-arguments-from-config/setup.cjs similarity index 100% rename from test/node-arguments/fixtures/node-arguments-from-config/setup.js rename to test/node-arguments/fixtures/node-arguments-from-config/setup.cjs diff --git a/test/node-arguments/fixtures/node-arguments/node-arguments.js b/test/node-arguments/fixtures/node-arguments/node-arguments.js index a73238f13..79a25e956 100644 --- a/test/node-arguments/fixtures/node-arguments/node-arguments.js +++ b/test/node-arguments/fixtures/node-arguments/node-arguments.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('exec arguments includes --throw-deprecation', t => { t.plan(1); diff --git a/test/node-arguments/fixtures/node-arguments/package.json b/test/node-arguments/fixtures/node-arguments/package.json index a0befd106..54f672450 100644 --- a/test/node-arguments/fixtures/node-arguments/package.json +++ b/test/node-arguments/fixtures/node-arguments/package.json @@ -1,4 +1,5 @@ { + "type": "module", "ava": { "files": [ "*.js" diff --git a/test/node-arguments/test.js b/test/node-arguments/test.js index afea10e3e..0fe9bda9d 100644 --- a/test/node-arguments/test.js +++ b/test/node-arguments/test.js @@ -1,33 +1,34 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {cleanOutput, cwd, fixture} from '../helpers/exec.js'; test('passed node arguments to workers', async t => { const options = { - cwd: exec.cwd('node-arguments') + cwd: cwd('node-arguments') }; // Removed --fill-zero-buffer because not supported in worker_threads - const result = await exec.fixture(['--node-arguments="--throw-deprecation"', 'node-arguments.js'], options); + const result = await fixture(['--node-arguments="--throw-deprecation"', 'node-arguments.js'], options); t.snapshot(result.stats.passed, 'tests pass'); }); test('detects incomplete --node-arguments', async t => { const options = { - cwd: exec.cwd('node-arguments') + cwd: cwd('node-arguments') }; - const result = await t.throwsAsync(exec.fixture(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], options)); + const result = await t.throwsAsync(fixture(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], options)); - t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('reads node arguments from config', async t => { const options = { - cwd: exec.cwd('node-arguments-from-config') + cwd: cwd('node-arguments-from-config') }; - const result = await exec.fixture(['node-arguments-from-config.js'], options); + const result = await fixture(['node-arguments-from-config.js'], options); t.snapshot(result.stats.passed, 'tests pass'); }); diff --git a/test/scheduler/fixtures/1pass.js b/test/scheduler/fixtures/1pass.js index 6155e5817..7b7c4b97d 100644 --- a/test/scheduler/fixtures/1pass.js +++ b/test/scheduler/fixtures/1pass.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('pass', t => { t.log(Date.now()); diff --git a/test/scheduler/fixtures/2fail.js b/test/scheduler/fixtures/2fail.js index 8b5468f4b..6f967c49a 100644 --- a/test/scheduler/fixtures/2fail.js +++ b/test/scheduler/fixtures/2fail.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('fail', t => { t.log(Date.now()); diff --git a/test/scheduler/fixtures/package.json b/test/scheduler/fixtures/package.json index f9b9cb835..54f672450 100644 --- a/test/scheduler/fixtures/package.json +++ b/test/scheduler/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "files": [ - "*.js" - ] - } + "type": "module", + "ava": { + "files": [ + "*.js" + ] + } } diff --git a/test/scheduler/test.js b/test/scheduler/test.js index b104527a1..1d75718ba 100644 --- a/test/scheduler/test.js +++ b/test/scheduler/test.js @@ -1,5 +1,6 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; const options = { // The scheduler only works when not in CI, so trick it into believing it is @@ -13,11 +14,11 @@ function getTimestamps(stats) { test.serial('failing tests come first', async t => { try { - await exec.fixture(['1pass.js', '2fail.js'], options); + await fixture(['1pass.js', '2fail.js'], options); } catch {} try { - await exec.fixture(['-t', '--concurrency=1', '1pass.js', '2fail.js'], options); + await fixture(['--concurrency=1', '1pass.js', '2fail.js'], options); } catch (error) { const timestamps = getTimestamps(error.stats); t.true(timestamps.failed < timestamps.passed); @@ -25,9 +26,9 @@ test.serial('failing tests come first', async t => { }); test.serial('scheduler disabled when cache empty', async t => { - await exec.fixture(['reset-cache'], options); // `ava reset-cache` resets the cache but does not run tests. + await fixture(['reset-cache'], options); // `ava reset-cache` resets the cache but does not run tests. try { - await exec.fixture(['-t', '--concurrency=1', '1pass.js', '2fail.js'], options); + await fixture(['--concurrency=1', '1pass.js', '2fail.js'], options); } catch (error) { const timestamps = getTimestamps(error.stats); t.true(timestamps.passed < timestamps.failed); @@ -36,11 +37,11 @@ test.serial('scheduler disabled when cache empty', async t => { test.serial('scheduler disabled when cache disabled', async t => { try { - await exec.fixture(['1pass.js', '2fail.js'], options); + await fixture(['1pass.js', '2fail.js'], options); } catch {} try { - await exec.fixture(['-t', '--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); + await fixture(['--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); } catch (error) { const timestamps = getTimestamps(error.stats); t.true(timestamps.passed < timestamps.failed); @@ -49,11 +50,11 @@ test.serial('scheduler disabled when cache disabled', async t => { test.serial('scheduler disabled in CI', async t => { try { - await exec.fixture(['1pass.js', '2fail.js'], {env: {AVA_FORCE_CI: 'ci'}}); + await fixture(['1pass.js', '2fail.js'], {env: {AVA_FORCE_CI: 'ci'}}); } catch {} try { - await exec.fixture(['-t', '--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); + await fixture(['--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); } catch (error) { const timestamps = getTimestamps(error.stats); t.true(timestamps.passed < timestamps.failed); diff --git a/test/shared-workers/cannot-publish-before-available/fixtures/_worker.js b/test/shared-workers/cannot-publish-before-available/fixtures/_worker.js index 6a922a379..577a89d9b 100644 --- a/test/shared-workers/cannot-publish-before-available/fixtures/_worker.js +++ b/test/shared-workers/cannot-publish-before-available/fixtures/_worker.js @@ -1,3 +1,3 @@ -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { negotiateProtocol(['experimental']).ready(); }; diff --git a/test/shared-workers/cannot-publish-before-available/fixtures/package.json b/test/shared-workers/cannot-publish-before-available/fixtures/package.json index e677ba947..82e3ddfc8 100644 --- a/test/shared-workers/cannot-publish-before-available/fixtures/package.json +++ b/test/shared-workers/cannot-publish-before-available/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/cannot-publish-before-available/fixtures/test.js b/test/shared-workers/cannot-publish-before-available/fixtures/test.js index 232965bfe..c8ef9661a 100644 --- a/test/shared-workers/cannot-publish-before-available/fixtures/test.js +++ b/test/shared-workers/cannot-publish-before-available/fixtures/test.js @@ -1,9 +1,9 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; test('cannot publish before ready', t => { const worker = plugin.registerSharedWorker({ - filename: require.resolve('./_worker'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/cannot-publish-before-available/test.js b/test/shared-workers/cannot-publish-before-available/test.js index 47b0fc7d3..7d4cb6c04 100644 --- a/test/shared-workers/cannot-publish-before-available/test.js +++ b/test/shared-workers/cannot-publish-before-available/test.js @@ -1,7 +1,8 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('shared worker plugins work', async t => { - const result = await exec.fixture(); + const result = await fixture(); t.snapshot(result.stats.passed); }); diff --git a/test/shared-workers/is-an-experiment/fixtures/package.json b/test/shared-workers/is-an-experiment/fixtures/package.json index 0967ef424..bedb411a9 100644 --- a/test/shared-workers/is-an-experiment/fixtures/package.json +++ b/test/shared-workers/is-an-experiment/fixtures/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/shared-workers/is-an-experiment/fixtures/test.js b/test/shared-workers/is-an-experiment/fixtures/test.js index 9f6cd0dd5..a22360a3a 100644 --- a/test/shared-workers/is-an-experiment/fixtures/test.js +++ b/test/shared-workers/is-an-experiment/fixtures/test.js @@ -1,4 +1,5 @@ -const plugin = require('ava/plugin'); +import * as plugin from 'ava/plugin'; + plugin.registerSharedWorker({ supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/is-an-experiment/test.js b/test/shared-workers/is-an-experiment/test.js index 9e66cb783..349d85c48 100644 --- a/test/shared-workers/is-an-experiment/test.js +++ b/test/shared-workers/is-an-experiment/test.js @@ -1,8 +1,9 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('opt-in is required', async t => { - const result = await t.throwsAsync(exec.fixture()); + const result = await t.throwsAsync(fixture()); t.is(result.exitCode, 1); t.is(result.stats.uncaughtExceptions.length, 1); t.snapshot(result.stats.uncaughtExceptions[0].message); diff --git a/test/shared-workers/lifecycle/fixtures/_worker.js b/test/shared-workers/lifecycle/fixtures/_worker.js index 56bbd6c58..1c7f791b8 100644 --- a/test/shared-workers/lifecycle/fixtures/_worker.js +++ b/test/shared-workers/lifecycle/fixtures/_worker.js @@ -1,3 +1,3 @@ -exports.default = ({negotiateProtocol}) => { +export default ({negotiateProtocol}) => { negotiateProtocol(['experimental']).ready(); }; diff --git a/test/shared-workers/lifecycle/fixtures/available.js b/test/shared-workers/lifecycle/fixtures/available.js index 40cf02228..aca67bdcf 100644 --- a/test/shared-workers/lifecycle/fixtures/available.js +++ b/test/shared-workers/lifecycle/fixtures/available.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; const worker = plugin.registerSharedWorker({ - filename: require.resolve('./_worker.js'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/lifecycle/fixtures/package.json b/test/shared-workers/lifecycle/fixtures/package.json index 2eb5f5a64..058b5540c 100644 --- a/test/shared-workers/lifecycle/fixtures/package.json +++ b/test/shared-workers/lifecycle/fixtures/package.json @@ -1,10 +1,11 @@ { - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "files": [ + "*" + ], + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/lifecycle/fixtures/teardown.js b/test/shared-workers/lifecycle/fixtures/teardown.js index ecb73b30d..1cc2c3128 100644 --- a/test/shared-workers/lifecycle/fixtures/teardown.js +++ b/test/shared-workers/lifecycle/fixtures/teardown.js @@ -1,10 +1,11 @@ -const assert = require('assert'); -const test = require('ava'); -const plugin = require('ava/plugin'); +import assert from 'assert'; + +import test from 'ava'; +import * as plugin from 'ava/plugin'; let calledLast = false; plugin.registerSharedWorker({ - filename: require.resolve('./_worker.js'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'], teardown() { assert(calledLast); @@ -13,7 +14,7 @@ plugin.registerSharedWorker({ }); plugin.registerSharedWorker({ - filename: require.resolve('./_worker.js'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'], teardown() { calledLast = true; diff --git a/test/shared-workers/lifecycle/test.js b/test/shared-workers/lifecycle/test.js index 611580ce2..1bc853943 100644 --- a/test/shared-workers/lifecycle/test.js +++ b/test/shared-workers/lifecycle/test.js @@ -1,11 +1,12 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('availability', async t => { - await t.notThrowsAsync(exec.fixture(['available.js'])); + await t.notThrowsAsync(fixture(['available.js'])); }); test('teardown', async t => { - const result = await exec.fixture('teardown.js'); + const result = await fixture('teardown.js'); t.true(result.stderr.includes('TEARDOWN CALLED')); }); diff --git a/test/shared-workers/restricted-to-worker-threads/fixtures/_worker.js b/test/shared-workers/restricted-to-worker-threads/fixtures/_worker.js index 6a922a379..577a89d9b 100644 --- a/test/shared-workers/restricted-to-worker-threads/fixtures/_worker.js +++ b/test/shared-workers/restricted-to-worker-threads/fixtures/_worker.js @@ -1,3 +1,3 @@ -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { negotiateProtocol(['experimental']).ready(); }; diff --git a/test/shared-workers/restricted-to-worker-threads/fixtures/package.json b/test/shared-workers/restricted-to-worker-threads/fixtures/package.json index e677ba947..82e3ddfc8 100644 --- a/test/shared-workers/restricted-to-worker-threads/fixtures/package.json +++ b/test/shared-workers/restricted-to-worker-threads/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/restricted-to-worker-threads/fixtures/test.js b/test/shared-workers/restricted-to-worker-threads/fixtures/test.js index c21b180ea..264d88a61 100644 --- a/test/shared-workers/restricted-to-worker-threads/fixtures/test.js +++ b/test/shared-workers/restricted-to-worker-threads/fixtures/test.js @@ -1,8 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; plugin.registerSharedWorker({ - filename: require.resolve('./_worker.js'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/restricted-to-worker-threads/test.js b/test/shared-workers/restricted-to-worker-threads/test.js index ae56a1e0d..0e0cf5feb 100644 --- a/test/shared-workers/restricted-to-worker-threads/test.js +++ b/test/shared-workers/restricted-to-worker-threads/test.js @@ -1,10 +1,11 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('can only be used when worker threads are enabled', async t => { - let result = await t.throwsAsync(exec.fixture(['--no-worker-threads'])); + let result = await t.throwsAsync(fixture(['--no-worker-threads'])); t.true(result.failed); t.true(result.stdout.includes('Error: Shared workers can be used only when worker threads are enabled')); - result = await exec.fixture([]); + result = await fixture([]); t.false(result.failed); }); diff --git a/test/shared-workers/supports-cjs-default-export/fixtures/_worker.js b/test/shared-workers/supports-cjs-default-export/fixtures/_worker.js deleted file mode 100644 index 56bbd6c58..000000000 --- a/test/shared-workers/supports-cjs-default-export/fixtures/_worker.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.default = ({negotiateProtocol}) => { - negotiateProtocol(['experimental']).ready(); -}; diff --git a/test/shared-workers/supports-cjs-default-export/fixtures/package.json b/test/shared-workers/supports-cjs-default-export/fixtures/package.json deleted file mode 100644 index 2eb5f5a64..000000000 --- a/test/shared-workers/supports-cjs-default-export/fixtures/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } -} diff --git a/test/shared-workers/supports-cjs-default-export/fixtures/test.js b/test/shared-workers/supports-cjs-default-export/fixtures/test.js deleted file mode 100644 index 96ab50cf0..000000000 --- a/test/shared-workers/supports-cjs-default-export/fixtures/test.js +++ /dev/null @@ -1,11 +0,0 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); - -const worker = plugin.registerSharedWorker({ - filename: require.resolve('./_worker.js'), - supportedProtocols: ['experimental'] -}); - -test('the shared worker becomes available', async t => { - await t.notThrowsAsync(worker.available); -}); diff --git a/test/shared-workers/supports-cjs-default-export/test.js b/test/shared-workers/supports-cjs-default-export/test.js deleted file mode 100644 index b4744df0b..000000000 --- a/test/shared-workers/supports-cjs-default-export/test.js +++ /dev/null @@ -1,6 +0,0 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); - -test('can load ESM workers', async t => { - await t.notThrowsAsync(exec.fixture()); -}); diff --git a/test/shared-workers/supports-esm-workers/fixtures/_worker.mjs b/test/shared-workers/supports-esm-workers/fixtures/_worker.mjs deleted file mode 100644 index 1c7f791b8..000000000 --- a/test/shared-workers/supports-esm-workers/fixtures/_worker.mjs +++ /dev/null @@ -1,3 +0,0 @@ -export default ({negotiateProtocol}) => { - negotiateProtocol(['experimental']).ready(); -}; diff --git a/test/shared-workers/supports-esm-workers/fixtures/file-url.js b/test/shared-workers/supports-esm-workers/fixtures/file-url.js deleted file mode 100644 index 87aa78f2d..000000000 --- a/test/shared-workers/supports-esm-workers/fixtures/file-url.js +++ /dev/null @@ -1,12 +0,0 @@ -const url = require('url'); -const test = require('ava'); -const plugin = require('ava/plugin'); - -const worker = plugin.registerSharedWorker({ - filename: url.pathToFileURL(require.resolve('./_worker.mjs')).toString(), - supportedProtocols: ['experimental'] -}); - -test('the shared worker becomes available', async t => { - await t.notThrowsAsync(worker.available); -}); diff --git a/test/shared-workers/supports-esm-workers/fixtures/package.json b/test/shared-workers/supports-esm-workers/fixtures/package.json deleted file mode 100644 index 2eb5f5a64..000000000 --- a/test/shared-workers/supports-esm-workers/fixtures/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } -} diff --git a/test/shared-workers/supports-esm-workers/fixtures/posix-path.js b/test/shared-workers/supports-esm-workers/fixtures/posix-path.js deleted file mode 100644 index c4f980fbd..000000000 --- a/test/shared-workers/supports-esm-workers/fixtures/posix-path.js +++ /dev/null @@ -1,11 +0,0 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); - -const worker = plugin.registerSharedWorker({ - filename: require.resolve('./_worker.mjs'), - supportedProtocols: ['experimental'] -}); - -test('the shared worker becomes available', async t => { - await t.notThrowsAsync(worker.available); -}); diff --git a/test/shared-workers/supports-esm-workers/test.js b/test/shared-workers/supports-esm-workers/test.js deleted file mode 100644 index 208e1745d..000000000 --- a/test/shared-workers/supports-esm-workers/test.js +++ /dev/null @@ -1,12 +0,0 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); - -test('can load ESM workers from file URL', async t => { - await t.notThrowsAsync(exec.fixture(['file-url.js'])); -}); - -if (process.platform !== 'win32') { - test('can load ESM workers from absolute posix path', async t => { - await t.notThrowsAsync(exec.fixture(['posix-path.js'])); - }); -} diff --git a/test/shared-workers/unsupported-protocol/fixtures/_worker.js b/test/shared-workers/unsupported-protocol/fixtures/_worker.js index 0c7c6c3c9..cf205d92a 100644 --- a/test/shared-workers/unsupported-protocol/fixtures/_worker.js +++ b/test/shared-workers/unsupported-protocol/fixtures/_worker.js @@ -1,3 +1,3 @@ -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { negotiateProtocol(['🙈']).ready(); }; diff --git a/test/shared-workers/unsupported-protocol/fixtures/in-shared-worker.js b/test/shared-workers/unsupported-protocol/fixtures/in-shared-worker.js index 7c1acc531..c492a4ba0 100644 --- a/test/shared-workers/unsupported-protocol/fixtures/in-shared-worker.js +++ b/test/shared-workers/unsupported-protocol/fixtures/in-shared-worker.js @@ -1,7 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; + plugin.registerSharedWorker({ - filename: require.resolve('./_worker'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/unsupported-protocol/fixtures/in-test-worker.js b/test/shared-workers/unsupported-protocol/fixtures/in-test-worker.js index e45268caf..09f680cdd 100644 --- a/test/shared-workers/unsupported-protocol/fixtures/in-test-worker.js +++ b/test/shared-workers/unsupported-protocol/fixtures/in-test-worker.js @@ -1,6 +1,6 @@ -const plugin = require('ava/plugin'); +import * as plugin from 'ava/plugin'; plugin.registerSharedWorker({ supportedProtocols: ['🙈'], - filename: __filename + filename: import.meta.url }); diff --git a/test/shared-workers/unsupported-protocol/fixtures/package.json b/test/shared-workers/unsupported-protocol/fixtures/package.json index 2eb5f5a64..058b5540c 100644 --- a/test/shared-workers/unsupported-protocol/fixtures/package.json +++ b/test/shared-workers/unsupported-protocol/fixtures/package.json @@ -1,10 +1,11 @@ { - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "files": [ + "*" + ], + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/unsupported-protocol/test.js b/test/shared-workers/unsupported-protocol/test.js index a8e50ba8e..dfd42260e 100644 --- a/test/shared-workers/unsupported-protocol/test.js +++ b/test/shared-workers/unsupported-protocol/test.js @@ -1,14 +1,15 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('must negotiate a supported protocol in the test worker', async t => { - const result = await t.throwsAsync(exec.fixture(['in-test-worker.js'])); + const result = await t.throwsAsync(fixture(['in-test-worker.js'])); const [uncaught] = result.stats.uncaughtExceptions; t.snapshot(uncaught.message.replace(/\([^)]+\)/, '(VERSION)')); }); test('must negotiate a supported protocol in the shared worker', async t => { - const result = await t.throwsAsync(exec.fixture(['in-shared-worker.js'])); + const result = await t.throwsAsync(fixture(['in-shared-worker.js'])); const [error] = result.stats.sharedWorkerErrors; t.snapshot(error.message.replace(/\([^)]+\)/, '(VERSION)').replace(/(shared worker plugin at).+$/, '$1 FILE')); }); diff --git a/test/shared-workers/worker-execution-crash/fixtures/_plugin.js b/test/shared-workers/worker-execution-crash/fixtures/_plugin.js index 614a4146a..97d92a6b4 100644 --- a/test/shared-workers/worker-execution-crash/fixtures/_plugin.js +++ b/test/shared-workers/worker-execution-crash/fixtures/_plugin.js @@ -1,6 +1,6 @@ -const plugin = require('ava/plugin'); +import * as plugin from 'ava/plugin'; -module.exports = plugin.registerSharedWorker({ - filename: require.resolve('./_worker'), +export default plugin.registerSharedWorker({ + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/worker-execution-crash/fixtures/_worker.js b/test/shared-workers/worker-execution-crash/fixtures/_worker.js index 5f53c7008..a64883c4a 100644 --- a/test/shared-workers/worker-execution-crash/fixtures/_worker.js +++ b/test/shared-workers/worker-execution-crash/fixtures/_worker.js @@ -1,4 +1,4 @@ -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { const protocol = negotiateProtocol(['experimental']); protocol.ready(); diff --git a/test/shared-workers/worker-execution-crash/fixtures/package.json b/test/shared-workers/worker-execution-crash/fixtures/package.json index e677ba947..82e3ddfc8 100644 --- a/test/shared-workers/worker-execution-crash/fixtures/package.json +++ b/test/shared-workers/worker-execution-crash/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/worker-execution-crash/fixtures/test.js b/test/shared-workers/worker-execution-crash/fixtures/test.js index 5f6831958..c9ded70d5 100644 --- a/test/shared-workers/worker-execution-crash/fixtures/test.js +++ b/test/shared-workers/worker-execution-crash/fixtures/test.js @@ -1,5 +1,6 @@ -const test = require('ava'); -const plugin = require('./_plugin'); +import test from 'ava'; + +import plugin from './_plugin.js'; test('shared workers crash', async t => { const replies = plugin.publish('🙈').replies(); diff --git a/test/shared-workers/worker-execution-crash/test.js b/test/shared-workers/worker-execution-crash/test.js index 21f962525..0cbea795b 100644 --- a/test/shared-workers/worker-execution-crash/test.js +++ b/test/shared-workers/worker-execution-crash/test.js @@ -1,8 +1,9 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('shared worker plugins work', async t => { - const result = await t.throwsAsync(exec.fixture()); + const result = await t.throwsAsync(fixture()); t.snapshot(result.stats.passed); t.is(result.stats.sharedWorkerErrors[0].message, '🙈'); }); diff --git a/test/shared-workers/worker-protocol/fixtures/_declare.js b/test/shared-workers/worker-protocol/fixtures/_declare.js index 9040d7a17..31899d4de 100644 --- a/test/shared-workers/worker-protocol/fixtures/_declare.js +++ b/test/shared-workers/worker-protocol/fixtures/_declare.js @@ -1,9 +1,11 @@ /* eslint-disable ava/no-ignored-test-files */ -const crypto = require('crypto'); -const test = require('ava'); -const plugin = require('./_plugin'); +import crypto from 'crypto'; -module.exports = testFile => { +import test from 'ava'; + +import plugin from './_plugin.js'; + +export default testFile => { test('becomes available', async t => { await t.notThrowsAsync(plugin.available); }); diff --git a/test/shared-workers/worker-protocol/fixtures/_plugin.js b/test/shared-workers/worker-protocol/fixtures/_plugin.js index 614a4146a..97d92a6b4 100644 --- a/test/shared-workers/worker-protocol/fixtures/_plugin.js +++ b/test/shared-workers/worker-protocol/fixtures/_plugin.js @@ -1,6 +1,6 @@ -const plugin = require('ava/plugin'); +import * as plugin from 'ava/plugin'; -module.exports = plugin.registerSharedWorker({ - filename: require.resolve('./_worker'), +export default plugin.registerSharedWorker({ + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/worker-protocol/fixtures/_worker.js b/test/shared-workers/worker-protocol/fixtures/_worker.js index f4184d86b..cdfbf2bad 100644 --- a/test/shared-workers/worker-protocol/fixtures/_worker.js +++ b/test/shared-workers/worker-protocol/fixtures/_worker.js @@ -1,4 +1,4 @@ -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { const protocol = negotiateProtocol(['experimental']); // When we're ready to receive workers or messages. diff --git a/test/shared-workers/worker-protocol/fixtures/other.test.js b/test/shared-workers/worker-protocol/fixtures/other.test.js index 74474e288..5f09aae47 100644 --- a/test/shared-workers/worker-protocol/fixtures/other.test.js +++ b/test/shared-workers/worker-protocol/fixtures/other.test.js @@ -1 +1,3 @@ -require('./_declare')(__filename); +import declare from './_declare.js'; + +declare(import.meta.url); diff --git a/test/shared-workers/worker-protocol/fixtures/package.json b/test/shared-workers/worker-protocol/fixtures/package.json index e677ba947..82e3ddfc8 100644 --- a/test/shared-workers/worker-protocol/fixtures/package.json +++ b/test/shared-workers/worker-protocol/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/worker-protocol/fixtures/test.js b/test/shared-workers/worker-protocol/fixtures/test.js index ffd952641..37b26179d 100644 --- a/test/shared-workers/worker-protocol/fixtures/test.js +++ b/test/shared-workers/worker-protocol/fixtures/test.js @@ -1,13 +1,14 @@ -const path = require('path'); -const test = require('ava'); -const plugin = require('./_plugin'); +import test from 'ava'; -require('./_declare')(__filename); +import declare from './_declare.js'; +import plugin from './_plugin.js'; + +declare(import.meta.url); test('test workers are released when they exit', async t => { for await (const message of plugin.subscribe()) { if ('cleanup' in message.data) { - t.is(message.data.cleanup, path.resolve(__dirname, 'other.test.js')); + t.is(message.data.cleanup, new URL('other.test.js', import.meta.url).toString()); return; } } diff --git a/test/shared-workers/worker-protocol/test.js b/test/shared-workers/worker-protocol/test.js index 47b0fc7d3..7d4cb6c04 100644 --- a/test/shared-workers/worker-protocol/test.js +++ b/test/shared-workers/worker-protocol/test.js @@ -1,7 +1,8 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('shared worker plugins work', async t => { - const result = await exec.fixture(); + const result = await fixture(); t.snapshot(result.stats.passed); }); diff --git a/test/shared-workers/worker-startup-crashes/fixtures/_factory-function.js b/test/shared-workers/worker-startup-crashes/fixtures/_factory-function.js index 8fb5d8ac4..64f354b61 100644 --- a/test/shared-workers/worker-startup-crashes/fixtures/_factory-function.js +++ b/test/shared-workers/worker-startup-crashes/fixtures/_factory-function.js @@ -1,3 +1,3 @@ -module.exports = () => { +export default () => { throw new Error('🙈'); }; diff --git a/test/shared-workers/worker-startup-crashes/fixtures/factory-function.js b/test/shared-workers/worker-startup-crashes/fixtures/factory-function.js index 48987b635..dab015494 100644 --- a/test/shared-workers/worker-startup-crashes/fixtures/factory-function.js +++ b/test/shared-workers/worker-startup-crashes/fixtures/factory-function.js @@ -1,7 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; + plugin.registerSharedWorker({ - filename: require.resolve('./_factory-function'), + filename: new URL('_factory-function.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/worker-startup-crashes/fixtures/module.js b/test/shared-workers/worker-startup-crashes/fixtures/module.js index 15a44e101..ac2ffce53 100644 --- a/test/shared-workers/worker-startup-crashes/fixtures/module.js +++ b/test/shared-workers/worker-startup-crashes/fixtures/module.js @@ -1,7 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; + plugin.registerSharedWorker({ - filename: require.resolve('./_module'), + filename: new URL('_module.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/worker-startup-crashes/fixtures/no-factory-function.js b/test/shared-workers/worker-startup-crashes/fixtures/no-factory-function.js index 260353f92..77babd8aa 100644 --- a/test/shared-workers/worker-startup-crashes/fixtures/no-factory-function.js +++ b/test/shared-workers/worker-startup-crashes/fixtures/no-factory-function.js @@ -1,7 +1,8 @@ -const test = require('ava'); -const plugin = require('ava/plugin'); +import test from 'ava'; +import * as plugin from 'ava/plugin'; + plugin.registerSharedWorker({ - filename: require.resolve('./_no-factory-function'), + filename: new URL('_no-factory-function.js', import.meta.url), supportedProtocols: ['experimental'] }); diff --git a/test/shared-workers/worker-startup-crashes/fixtures/package.json b/test/shared-workers/worker-startup-crashes/fixtures/package.json index 2eb5f5a64..058b5540c 100644 --- a/test/shared-workers/worker-startup-crashes/fixtures/package.json +++ b/test/shared-workers/worker-startup-crashes/fixtures/package.json @@ -1,10 +1,11 @@ { - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "files": [ + "*" + ], + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/worker-startup-crashes/test.js b/test/shared-workers/worker-startup-crashes/test.js index e3a12059a..74ed80504 100644 --- a/test/shared-workers/worker-startup-crashes/test.js +++ b/test/shared-workers/worker-startup-crashes/test.js @@ -1,20 +1,21 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('handles crashes in factory function', async t => { - const result = await t.throwsAsync(exec.fixture(['factory-function.js'])); + const result = await t.throwsAsync(fixture(['factory-function.js'])); const [error] = result.stats.sharedWorkerErrors; t.is(error.message, '🙈'); }); test('handles crashes in when there is no factory function', async t => { - const result = await t.throwsAsync(exec.fixture(['no-factory-function.js'])); + const result = await t.throwsAsync(fixture(['no-factory-function.js'])); const [error] = result.stats.sharedWorkerErrors; t.snapshot(error.message.replace(/(shared worker plugin at).+$/, '$1 FILE')); }); test('handles crashes in loading worker module', async t => { - const result = await t.throwsAsync(exec.fixture(['module.js'])); + const result = await t.throwsAsync(fixture(['module.js'])); const [error] = result.stats.sharedWorkerErrors; t.is(error.message, '🙊'); }); diff --git a/test/shared-workers/workers-are-loaded-once/fixtures/_plugin.js b/test/shared-workers/workers-are-loaded-once/fixtures/_plugin.js index 4a513868e..a02312f09 100644 --- a/test/shared-workers/workers-are-loaded-once/fixtures/_plugin.js +++ b/test/shared-workers/workers-are-loaded-once/fixtures/_plugin.js @@ -1,9 +1,9 @@ -const plugin = require('ava/plugin'); -const itFirst = require('it-first'); +import * as plugin from 'ava/plugin'; +import itFirst from 'it-first'; const worker = plugin.registerSharedWorker({ - filename: require.resolve('./_worker'), + filename: new URL('_worker.js', import.meta.url), supportedProtocols: ['experimental'] }); -exports.random = itFirst(worker.subscribe()); +export const random = itFirst(worker.subscribe()); diff --git a/test/shared-workers/workers-are-loaded-once/fixtures/_worker.js b/test/shared-workers/workers-are-loaded-once/fixtures/_worker.js index 9e6683bd5..9aefd2180 100644 --- a/test/shared-workers/workers-are-loaded-once/fixtures/_worker.js +++ b/test/shared-workers/workers-are-loaded-once/fixtures/_worker.js @@ -1,6 +1,6 @@ -const crypto = require('crypto'); +import crypto from 'crypto'; -module.exports = async ({negotiateProtocol}) => { +export default async ({negotiateProtocol}) => { const protocol = negotiateProtocol(['experimental']).ready(); const random = crypto.randomBytes(16).toString('hex'); diff --git a/test/shared-workers/workers-are-loaded-once/fixtures/package.json b/test/shared-workers/workers-are-loaded-once/fixtures/package.json index 2eb5f5a64..058b5540c 100644 --- a/test/shared-workers/workers-are-loaded-once/fixtures/package.json +++ b/test/shared-workers/workers-are-loaded-once/fixtures/package.json @@ -1,10 +1,11 @@ { - "ava": { - "files": [ - "*" - ], - "nonSemVerExperiments": { - "sharedWorkers": true - } - } + "type": "module", + "ava": { + "files": [ + "*" + ], + "nonSemVerExperiments": { + "sharedWorkers": true + } + } } diff --git a/test/shared-workers/workers-are-loaded-once/fixtures/test-1.js b/test/shared-workers/workers-are-loaded-once/fixtures/test-1.js index ab3f260b6..ad2d23781 100644 --- a/test/shared-workers/workers-are-loaded-once/fixtures/test-1.js +++ b/test/shared-workers/workers-are-loaded-once/fixtures/test-1.js @@ -1,5 +1,6 @@ -const test = require('ava'); -const {random} = require('./_plugin'); +import test from 'ava'; + +import {random} from './_plugin.js'; test('the shared worker produces a random value', async t => { const {data} = await random; diff --git a/test/shared-workers/workers-are-loaded-once/fixtures/test-2.js b/test/shared-workers/workers-are-loaded-once/fixtures/test-2.js index ab3f260b6..ad2d23781 100644 --- a/test/shared-workers/workers-are-loaded-once/fixtures/test-2.js +++ b/test/shared-workers/workers-are-loaded-once/fixtures/test-2.js @@ -1,5 +1,6 @@ -const test = require('ava'); -const {random} = require('./_plugin'); +import test from 'ava'; + +import {random} from './_plugin.js'; test('the shared worker produces a random value', async t => { const {data} = await random; diff --git a/test/shared-workers/workers-are-loaded-once/test.js b/test/shared-workers/workers-are-loaded-once/test.js index 217938957..71160a9e1 100644 --- a/test/shared-workers/workers-are-loaded-once/test.js +++ b/test/shared-workers/workers-are-loaded-once/test.js @@ -1,8 +1,9 @@ -const test = require('@ava/test'); -const exec = require('../../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../../helpers/exec.js'; test('shared workers are loaded only once', async t => { - const result = await exec.fixture(); + const result = await fixture(); const logs = result.stats.passed.map(object => result.stats.getLogs(object)); t.is(logs.length, 2); t.deepEqual(logs[0], logs[1]); diff --git a/test/snapshot-order/fixtures/intertest-order/package.json b/test/snapshot-order/fixtures/intertest-order/package.json index 0967ef424..bedb411a9 100644 --- a/test/snapshot-order/fixtures/intertest-order/package.json +++ b/test/snapshot-order/fixtures/intertest-order/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/snapshot-order/fixtures/intertest-order/test.js b/test/snapshot-order/fixtures/intertest-order/test.js index 79081b23b..6f66a4541 100644 --- a/test/snapshot-order/fixtures/intertest-order/test.js +++ b/test/snapshot-order/fixtures/intertest-order/test.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; const reverse = process.env.INTERTEST_ORDER_REVERSE; diff --git a/test/snapshot-order/fixtures/randomness/package.json b/test/snapshot-order/fixtures/randomness/package.json index 0967ef424..bedb411a9 100644 --- a/test/snapshot-order/fixtures/randomness/package.json +++ b/test/snapshot-order/fixtures/randomness/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/snapshot-order/fixtures/randomness/test.js b/test/snapshot-order/fixtures/randomness/test.js index 43d7525c1..5c79c387a 100644 --- a/test/snapshot-order/fixtures/randomness/test.js +++ b/test/snapshot-order/fixtures/randomness/test.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; const id = index => `index: ${index}`; const randomDelay = () => new Promise(resolve => { diff --git a/test/snapshot-order/fixtures/report-declaration-order/package.json b/test/snapshot-order/fixtures/report-declaration-order/package.json index 0967ef424..bedb411a9 100644 --- a/test/snapshot-order/fixtures/report-declaration-order/package.json +++ b/test/snapshot-order/fixtures/report-declaration-order/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/snapshot-order/fixtures/report-declaration-order/test.js b/test/snapshot-order/fixtures/report-declaration-order/test.js index 9ee83c067..ef93affbd 100644 --- a/test/snapshot-order/fixtures/report-declaration-order/test.js +++ b/test/snapshot-order/fixtures/report-declaration-order/test.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; const id = index => `index: ${index}`; diff --git a/test/snapshot-order/helpers/get-snapshot-ids.js b/test/snapshot-order/helpers/get-snapshot-ids.js index 00c376b4c..e78331c7b 100644 --- a/test/snapshot-order/helpers/get-snapshot-ids.js +++ b/test/snapshot-order/helpers/get-snapshot-ids.js @@ -1,4 +1,4 @@ -function getSnapshotIds(report) { +export default function getSnapshotIds(report) { function * matchAll(string, regexp) { let match; while ((match = regexp.exec(string)) !== null) { @@ -10,5 +10,3 @@ function getSnapshotIds(report) { return ids; } - -module.exports = getSnapshotIds; diff --git a/test/snapshot-order/intertest-order.js b/test/snapshot-order/intertest-order.js index 6324f92b7..1209bd58f 100644 --- a/test/snapshot-order/intertest-order.js +++ b/test/snapshot-order/intertest-order.js @@ -1,11 +1,13 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; + +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; test('snapshot files are independent of test resolution order', async t => { const options = { - cwd: exec.cwd('intertest-order'), + cwd: cwd('intertest-order'), env: { AVA_FORCE_CI: 'not-ci' } @@ -20,13 +22,13 @@ test('snapshot files are independent of test resolution order', async t => { }); // Run, updating snapshots. - await exec.fixture(['test.js', '--update-snapshots'], options); + await fixture(['test.js', '--update-snapshots'], options); // Read the resulting file const snapshot = fs.readFileSync(snapshotPath); // Run in reversed order, updating snapshots. - await exec.fixture(['test.js', '--update-snapshots'], { + await fixture(['test.js', '--update-snapshots'], { ...options, env: { INTERTEST_ORDER_REVERSE: 'true', diff --git a/test/snapshot-order/randomness.js b/test/snapshot-order/randomness.js index 92078f907..b7393c264 100644 --- a/test/snapshot-order/randomness.js +++ b/test/snapshot-order/randomness.js @@ -1,12 +1,15 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const fs = require('fs'); -const path = require('path'); -const getSnapshotIds = require('./helpers/get-snapshot-ids'); +import fs from 'fs'; +import path from 'path'; + +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; + +import getSnapshotIds from './helpers/get-snapshot-ids.js'; test('deterministic and sorted over a large, random test case', async t => { const options = { - cwd: exec.cwd('randomness'), + cwd: cwd('randomness'), env: { AVA_FORCE_CI: 'not-ci' } @@ -16,7 +19,7 @@ test('deterministic and sorted over a large, random test case', async t => { const reportPath = path.join(options.cwd, 'test.js.md'); // Run test - await exec.fixture(['--update-snapshots'], options); + await fixture(['--update-snapshots'], options); // Assert snapshot is unchanged const snapshot = fs.readFileSync(snapshotPath); diff --git a/test/snapshot-order/report-declaration-order.js b/test/snapshot-order/report-declaration-order.js index 62eb85e44..5fe31efaf 100644 --- a/test/snapshot-order/report-declaration-order.js +++ b/test/snapshot-order/report-declaration-order.js @@ -1,12 +1,15 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const fs = require('fs'); -const path = require('path'); -const getSnapshotIds = require('./helpers/get-snapshot-ids'); +import fs from 'fs'; +import path from 'path'; + +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; + +import getSnapshotIds from './helpers/get-snapshot-ids.js'; test('snapshot reports are sorted in declaration order', async t => { const options = { - cwd: exec.cwd('report-declaration-order'), + cwd: cwd('report-declaration-order'), env: { AVA_FORCE_CI: 'not-ci' } @@ -18,7 +21,7 @@ test('snapshot reports are sorted in declaration order', async t => { fs.unlinkSync(reportPath); }); - await exec.fixture(['--update-snapshots'], options); + await fixture(['--update-snapshots'], options); const reportPath = path.join(options.cwd, 'test.js.md'); diff --git a/test/snapshot-regenerate-report/fixtures/package.json b/test/snapshot-regenerate-report/fixtures/package.json index 0967ef424..bedb411a9 100644 --- a/test/snapshot-regenerate-report/fixtures/package.json +++ b/test/snapshot-regenerate-report/fixtures/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/snapshot-regenerate-report/fixtures/test.js b/test/snapshot-regenerate-report/fixtures/test.js index 29245bd3f..74dc9dfec 100644 --- a/test/snapshot-regenerate-report/fixtures/test.js +++ b/test/snapshot-regenerate-report/fixtures/test.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; function randomDelay(max) { return new Promise(resolve => { diff --git a/test/snapshot-regenerate-report/test.js b/test/snapshot-regenerate-report/test.js index aa63810d7..272351c46 100644 --- a/test/snapshot-regenerate-report/test.js +++ b/test/snapshot-regenerate-report/test.js @@ -1,25 +1,28 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import {promises as fs} from 'fs'; +import path from 'path'; -const fs = require('fs').promises; -const path = require('path'); +import test from '@ava/test'; -require('../../lib/chalk').set({level: 0}); -require('../../lib/worker/options').set({}); -const {load} = require('../../lib/snapshot-manager'); +import {set as setChalk} from '../../lib/chalk.js'; +import {load} from '../../lib/snapshot-manager.js'; +import {set as setOptions} from '../../lib/worker/options.cjs'; +import {cwd, fixture} from '../helpers/exec.js'; + +setChalk({level: 0}); +setOptions({}); test('snapshot report can be regenerated from .snap file', async t => { - const cwd = exec.cwd(); + const workingDir = cwd(); const env = { AVA_FORCE_CI: 'not-ci' }; - const reportPath = path.join(cwd, 'test.js.md'); + const reportPath = path.join(workingDir, 'test.js.md'); t.teardown(() => fs.unlink(reportPath)); - t.teardown(() => fs.unlink(path.join(cwd, 'test.js.snap'))); + t.teardown(() => fs.unlink(path.join(workingDir, 'test.js.snap'))); // Run fixture to generate report, snapshot - await exec.fixture(['--update-snapshots'], {cwd, env}); + await fixture(['--update-snapshots'], {cwd: workingDir, env}); // Read report const report = await fs.readFile(reportPath, 'utf8'); @@ -29,8 +32,8 @@ test('snapshot report can be regenerated from .snap file', async t => { // Load snapshot manager from .snap file const snapshots = load({ - file: path.join(cwd, 'test.js'), - projectDir: cwd + file: path.join(workingDir, 'test.js'), + projectDir: workingDir }); // Regenerate report diff --git a/test/snapshot-removal/fixtures/fixed-snapshot-dir/package.json b/test/snapshot-removal/fixtures/fixed-snapshot-dir/package.json index 6aa55350f..72f103e52 100644 --- a/test/snapshot-removal/fixtures/fixed-snapshot-dir/package.json +++ b/test/snapshot-removal/fixtures/fixed-snapshot-dir/package.json @@ -1,5 +1,5 @@ { - "ava": { - "snapshotDir": "fixedSnapshotDir" - } + "ava": { + "snapshotDir": "fixedSnapshotDir" + } } diff --git a/test/snapshot-removal/helpers/macros.js b/test/snapshot-removal/helpers/macros.js index 61ae9b997..5611fe75c 100644 --- a/test/snapshot-removal/helpers/macros.js +++ b/test/snapshot-removal/helpers/macros.js @@ -1,9 +1,10 @@ -const fs = require('fs').promises; -const exec = require('../../helpers/exec'); -const path = require('path'); -const {withTemporaryFixture} = require('../../helpers/with-temporary-fixture'); +import {promises as fs} from 'fs'; +import path from 'path'; -async function testSnapshotPruning(t, { +import {fixture} from '../../helpers/exec.js'; +import {withTemporaryFixture} from '../../helpers/with-temporary-fixture.js'; + +export async function testSnapshotPruning(t, { cwd, env, cli, @@ -18,7 +19,7 @@ async function testSnapshotPruning(t, { if (updating) { // Execute fixture as template to generate snapshots - const templateResult = exec.fixture(['--update-snapshots'], { + const templateResult = fixture(['--update-snapshots'], { cwd, env: { AVA_FORCE_CI: 'not-ci', @@ -40,7 +41,7 @@ async function testSnapshotPruning(t, { // Make a temporary copy of the fixture await withTemporaryFixture(cwd, async cwd => { // Execute fixture as run - const run = exec.fixture(cli, { + const run = fixture(cli, { cwd, env: { AVA_FORCE_CI: 'not-ci', @@ -68,5 +69,3 @@ async function testSnapshotPruning(t, { } }); } - -module.exports.testSnapshotPruning = testSnapshotPruning; diff --git a/test/snapshot-removal/test.js b/test/snapshot-removal/test.js index a2c8e7c5b..134f21c31 100644 --- a/test/snapshot-removal/test.js +++ b/test/snapshot-removal/test.js @@ -1,9 +1,12 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {testSnapshotPruning} = require('./helpers/macros'); -const {withTemporaryFixture} = require('../helpers/with-temporary-fixture'); -const fs = require('fs').promises; -const path = require('path'); +import {promises as fs} from 'fs'; +import path from 'path'; + +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; +import {withTemporaryFixture} from '../helpers/with-temporary-fixture.js'; + +import {testSnapshotPruning} from './helpers/macros.js'; // To update the test fixture templates, run: // npx test-ava test/snapshot-removal/** -- --update-fixture-snapshots @@ -11,13 +14,13 @@ const path = require('path'); // Serial execution is used here solely to reduce the burden on CI machines. test.serial('snapshots are removed when tests stop using them', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['--update-snapshots'], remove: true }); test.serial('snapshots are removed from a snapshot directory', testSnapshotPruning, { - cwd: exec.cwd('snapshot-dir'), + cwd: cwd('snapshot-dir'), cli: ['--update-snapshots'], remove: true, snapshotFile: path.join('test', 'snapshots', 'test.js.snap'), @@ -25,7 +28,7 @@ test.serial('snapshots are removed from a snapshot directory', testSnapshotPruni }); test.serial('snapshots are removed from a custom snapshotDir', testSnapshotPruning, { - cwd: exec.cwd('fixed-snapshot-dir'), + cwd: cwd('fixed-snapshot-dir'), cli: ['--update-snapshots'], remove: true, snapshotFile: path.join('fixedSnapshotDir', 'test.js.snap'), @@ -33,10 +36,10 @@ test.serial('snapshots are removed from a custom snapshotDir', testSnapshotPruni }); test.serial('removing non-existent snapshots doesn\'t throw', async t => { - await withTemporaryFixture(exec.cwd('no-snapshots'), async cwd => { + await withTemporaryFixture(cwd('no-snapshots'), async cwd => { // Execute fixture; this should try to unlink the nonexistent snapshots, and // should not throw - const run = exec.fixture(['--update-snapshots'], { + const run = fixture(['--update-snapshots'], { cwd, env: { AVA_FORCE_CI: 'not-ci' @@ -48,12 +51,12 @@ test.serial('removing non-existent snapshots doesn\'t throw', async t => { }); test.serial('without --update-snapshots, invalid .snaps are retained', async t => { - await withTemporaryFixture(exec.cwd('no-snapshots'), async cwd => { + await withTemporaryFixture(cwd('no-snapshots'), async cwd => { const snapPath = path.join(cwd, 'test.js.snap'); const invalid = Buffer.of(0x0A, 0x00, 0x00); await fs.writeFile(snapPath, invalid); - await exec.fixture([], {cwd}); + await fixture([], {cwd}); await t.notThrowsAsync(fs.access(snapPath)); t.deepEqual(await fs.readFile(snapPath), invalid); @@ -61,25 +64,25 @@ test.serial('without --update-snapshots, invalid .snaps are retained', async t = }); test.serial('with --update-snapshots, invalid .snaps are removed', async t => { - await withTemporaryFixture(exec.cwd('no-snapshots'), async cwd => { + await withTemporaryFixture(cwd('no-snapshots'), async cwd => { const snapPath = path.join(cwd, 'test.js.snap'); const invalid = Buffer.of(0x0A, 0x00, 0x00); await fs.writeFile(snapPath, invalid); - await exec.fixture(['--update-snapshots'], {cwd}); + await fixture(['--update-snapshots'], {cwd}); await t.throwsAsync(fs.access(snapPath), {code: 'ENOENT'}, 'Expected snapshot to be removed'); }); }); test.serial('snapshots remain if not updating', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: [], remove: false }); test.serial('snapshots remain if they are still used', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['--update-snapshots'], remove: false, env: { @@ -93,7 +96,7 @@ test.serial('snapshots remain if they are still used', testSnapshotPruning, { }); test.serial('snapshots remain if tests run with --match', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['--update-snapshots', '--match=\'*another*\''], remove: false, checkRun: async (t, run) => { @@ -104,7 +107,7 @@ test.serial('snapshots remain if tests run with --match', testSnapshotPruning, { }); test.serial('snapshots removed if --match selects all tests', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['--update-snapshots', '--match=\'*snapshot*\''], remove: true, checkRun: async (t, run) => { @@ -115,7 +118,7 @@ test.serial('snapshots removed if --match selects all tests', testSnapshotPrunin }); test.serial('snapshots remain if tests selected by line numbers', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['test.js:10-17', '--update-snapshots'], remove: false, checkRun: async (t, run) => { @@ -126,7 +129,7 @@ test.serial('snapshots remain if tests selected by line numbers', testSnapshotPr }); test.serial('snapshots removed if line numbers select all tests', testSnapshotPruning, { - cwd: exec.cwd('removal'), + cwd: cwd('removal'), cli: ['test.js:0-100', '--update-snapshots'], remove: true, checkRun: async (t, run) => { @@ -137,7 +140,7 @@ test.serial('snapshots removed if line numbers select all tests', testSnapshotPr }); test.serial('snapshots remain if using test.only', testSnapshotPruning, { - cwd: exec.cwd('only-test'), + cwd: cwd('only-test'), cli: ['--update-snapshots'], remove: false, checkRun: async (t, run) => { @@ -146,7 +149,7 @@ test.serial('snapshots remain if using test.only', testSnapshotPruning, { }); test.serial('snapshots remain if tests are skipped', testSnapshotPruning, { - cwd: exec.cwd('skipped-tests'), + cwd: cwd('skipped-tests'), cli: ['--update-snapshots'], remove: false, checkRun: async (t, run) => { @@ -155,7 +158,7 @@ test.serial('snapshots remain if tests are skipped', testSnapshotPruning, { }); test.serial('snapshots remain if snapshot assertions are skipped', testSnapshotPruning, { - cwd: exec.cwd('skipped-snapshots'), + cwd: cwd('skipped-snapshots'), cli: ['--update-snapshots'], remove: false, checkRun: async (t, run) => { @@ -166,7 +169,7 @@ test.serial('snapshots remain if snapshot assertions are skipped', testSnapshotP // This behavior is consistent with the expectation that discarded attempts // should have no effect. test.serial('snapshots removed if used in a discarded try()', testSnapshotPruning, { - cwd: exec.cwd('try'), + cwd: cwd('try'), cli: ['--update-snapshots'], remove: true }); @@ -174,7 +177,7 @@ test.serial('snapshots removed if used in a discarded try()', testSnapshotPrunin // This behavior is consistent with the expectation that discarded attempts // should have no effect. test.serial('snapshots removed if skipped in a discarded try()', testSnapshotPruning, { - cwd: exec.cwd('skipped-snapshots-in-try'), + cwd: cwd('skipped-snapshots-in-try'), cli: ['--update-snapshots'], remove: true, checkRun: async (t, run) => { diff --git a/test/snapshot-workflow/adding.js b/test/snapshot-workflow/adding.js index ebbd7c252..09bef75e3 100644 --- a/test/snapshot-workflow/adding.js +++ b/test/snapshot-workflow/adding.js @@ -1,18 +1,20 @@ -const test = require('@ava/test'); +import {promises as fs} from 'fs'; +import path from 'path'; -const exec = require('../helpers/exec'); -const path = require('path'); -const fs = require('fs').promises; -const {beforeAndAfter} = require('./helpers/macros'); -const {withTemporaryFixture} = require('../helpers/with-temporary-fixture'); +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; +import {withTemporaryFixture} from '../helpers/with-temporary-fixture.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial('First run generates a .snap and a .md', async t => { - await withTemporaryFixture(exec.cwd('first-run'), async cwd => { + await withTemporaryFixture(cwd('first-run'), async cwd => { const env = { AVA_FORCE_CI: 'not-ci' }; - await exec.fixture([], {cwd, env}); + await fixture([], {cwd, env}); const [, report] = await Promise.all([ t.notThrowsAsync(fs.access(path.join(cwd, 'test.js.snap'))), @@ -26,7 +28,7 @@ test.serial( 'Adding more snapshots to a test adds them to the .snap and .md', beforeAndAfter, { - cwd: exec.cwd('adding-snapshots'), + cwd: cwd('adding-snapshots'), expectChanged: true } ); @@ -35,7 +37,7 @@ test.serial( 'Adding a test with snapshots adds them to the .snap and .md', beforeAndAfter, { - cwd: exec.cwd('adding-test'), + cwd: cwd('adding-test'), expectChanged: true } ); @@ -44,7 +46,7 @@ test.serial( 'Changing a test\'s title adds a new block, puts the old block at the end', beforeAndAfter, { - cwd: exec.cwd('changing-title'), + cwd: cwd('changing-title'), expectChanged: true } ); @@ -53,7 +55,7 @@ test.serial( 'Adding skipped snapshots followed by unskipped snapshots records blanks', beforeAndAfter, { - cwd: exec.cwd('adding-skipped-snapshots'), + cwd: cwd('adding-skipped-snapshots'), expectChanged: true } ); @@ -62,7 +64,7 @@ test.serial( 'Filling in blanks doesn\'t require --update-snapshots', beforeAndAfter, { - cwd: exec.cwd('filling-in-blanks'), + cwd: cwd('filling-in-blanks'), expectChanged: true } ); diff --git a/test/snapshot-workflow/changing-label.js b/test/snapshot-workflow/changing-label.js index 948978bc7..5bfe8d4ac 100644 --- a/test/snapshot-workflow/changing-label.js +++ b/test/snapshot-workflow/changing-label.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'Changing a snapshot\'s label does not change the .snap or .md', beforeAndAfter, { - cwd: exec.cwd('changing-label'), + cwd: cwd('changing-label'), expectChanged: false } ); @@ -15,7 +17,7 @@ test.serial( 'With --update-snapshots, changing a snapshot\'s label updates the .snap and .md', beforeAndAfter, { - cwd: exec.cwd('changing-label'), + cwd: cwd('changing-label'), cli: ['--update-snapshots'], expectChanged: true } diff --git a/test/snapshot-workflow/helpers/macros.js b/test/snapshot-workflow/helpers/macros.js index 8be458c9d..5a3fb659c 100644 --- a/test/snapshot-workflow/helpers/macros.js +++ b/test/snapshot-workflow/helpers/macros.js @@ -1,8 +1,11 @@ -const exec = require('../../helpers/exec'); -const path = require('path'); -const fs = require('fs').promises; -const concordance = require('concordance'); -const {withTemporaryFixture} = require('../../helpers/with-temporary-fixture'); + +import {promises as fs} from 'fs'; +import path from 'path'; + +import concordance from 'concordance'; + +import {fixture} from '../../helpers/exec.js'; +import {withTemporaryFixture} from '../../helpers/with-temporary-fixture.js'; function cleanStringDiff(before, after) { const theme = { @@ -20,7 +23,7 @@ function cleanStringDiff(before, after) { return diff; } -async function beforeAndAfter(t, { +export async function beforeAndAfter(t, { cwd, expectChanged, env = {}, @@ -30,7 +33,7 @@ async function beforeAndAfter(t, { if (updating) { // Run template - await exec.fixture(['--update-snapshots'], { + await fixture(['--update-snapshots'], { cwd, env: { TEMPLATE: 'true', @@ -44,7 +47,7 @@ async function beforeAndAfter(t, { // Copy fixture to a temporary directory await withTemporaryFixture(cwd, async cwd => { // Run fixture - await exec.fixture(cli, {cwd, env: {AVA_FORCE_CI: 'not-ci', ...env}}); + await fixture(cli, {cwd, env: {AVA_FORCE_CI: 'not-ci', ...env}}); const after = await readSnapshots(cwd); @@ -59,8 +62,6 @@ async function beforeAndAfter(t, { }); } -exports.beforeAndAfter = beforeAndAfter; - async function readSnapshots(cwd) { const [snapshot, report] = await Promise.all([ fs.readFile(path.join(cwd, 'test.js.snap')), diff --git a/test/snapshot-workflow/invalid-snapfile.js b/test/snapshot-workflow/invalid-snapfile.js index f7f2f3d13..1841b3174 100644 --- a/test/snapshot-workflow/invalid-snapfile.js +++ b/test/snapshot-workflow/invalid-snapfile.js @@ -1,18 +1,20 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const fs = require('fs').promises; -const path = require('path'); -const {withTemporaryFixture} = require('../helpers/with-temporary-fixture'); +import {promises as fs} from 'fs'; +import path from 'path'; + +import test from '@ava/test'; + +import {cwd, fixture} from '../helpers/exec.js'; +import {withTemporaryFixture} from '../helpers/with-temporary-fixture.js'; test.serial('With invalid .snap file and --update-snapshots, skipped snaps are omitted', async t => { - await withTemporaryFixture(exec.cwd('invalid-snapfile'), async cwd => { + await withTemporaryFixture(cwd('invalid-snapfile'), async cwd => { const env = {AVA_FORCE_CI: 'not-ci'}; const snapPath = path.join(cwd, 'test.js.snap'); const reportPath = path.join(cwd, 'test.js.md'); await fs.writeFile(snapPath, Buffer.of(0x0A, 0x00, 0x00)); - const result = await exec.fixture(['--update-snapshots'], {cwd, env}); + const result = await fixture(['--update-snapshots'], {cwd, env}); const report = await fs.readFile(reportPath, 'utf8'); t.snapshot(report, 'snapshot report'); diff --git a/test/snapshot-workflow/removing-all-snapshots.js b/test/snapshot-workflow/removing-all-snapshots.js index df04f4242..d74d03b8f 100644 --- a/test/snapshot-workflow/removing-all-snapshots.js +++ b/test/snapshot-workflow/removing-all-snapshots.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'Removing all snapshots from a test retains its data', beforeAndAfter, { - cwd: exec.cwd('removing-all-snapshots'), + cwd: cwd('removing-all-snapshots'), expectChanged: false } ); @@ -15,7 +17,7 @@ test.serial( 'With --update-snapshots, removing all snapshots from a test removes the block', beforeAndAfter, { - cwd: exec.cwd('removing-all-snapshots'), + cwd: cwd('removing-all-snapshots'), cli: ['--update-snapshots'], expectChanged: true } diff --git a/test/snapshot-workflow/removing-snapshots.js b/test/snapshot-workflow/removing-snapshots.js index 2a3698519..985798b03 100644 --- a/test/snapshot-workflow/removing-snapshots.js +++ b/test/snapshot-workflow/removing-snapshots.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'Removing a snapshot assertion retains its data', beforeAndAfter, { - cwd: exec.cwd('removing-snapshots'), + cwd: cwd('removing-snapshots'), expectChanged: false } ); @@ -15,7 +17,7 @@ test.serial( 'With --update-snapshots, removing a snapshot assertion removes its data', beforeAndAfter, { - cwd: exec.cwd('removing-snapshots'), + cwd: cwd('removing-snapshots'), cli: ['--update-snapshots'], expectChanged: true } diff --git a/test/snapshot-workflow/removing-test.js b/test/snapshot-workflow/removing-test.js index 581ded8d2..b52e88ed4 100644 --- a/test/snapshot-workflow/removing-test.js +++ b/test/snapshot-workflow/removing-test.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'Removing a test retains its data', beforeAndAfter, { - cwd: exec.cwd('removing-test'), + cwd: cwd('removing-test'), expectChanged: false } ); @@ -15,7 +17,7 @@ test.serial( 'With --update-snapshots, removing a test removes its block', beforeAndAfter, { - cwd: exec.cwd('removing-test'), + cwd: cwd('removing-test'), cli: ['--update-snapshots'], expectChanged: true } diff --git a/test/snapshot-workflow/reorder.js b/test/snapshot-workflow/reorder.js index d07b94e19..89f47dd27 100644 --- a/test/snapshot-workflow/reorder.js +++ b/test/snapshot-workflow/reorder.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'Reordering tests does not change the .snap or .md', beforeAndAfter, { - cwd: exec.cwd('reorder'), + cwd: cwd('reorder'), expectChanged: false } ); @@ -15,7 +17,7 @@ test.serial( 'With --update-snapshots, reordering tests reorders the .snap and .md', beforeAndAfter, { - cwd: exec.cwd('reorder'), + cwd: cwd('reorder'), cli: ['--update-snapshots'], expectChanged: true } diff --git a/test/snapshot-workflow/selection.js b/test/snapshot-workflow/selection.js index c6651ea7f..d4cff57d7 100644 --- a/test/snapshot-workflow/selection.js +++ b/test/snapshot-workflow/selection.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 'With --update-snapshots, skipping snapshots preserves their data', beforeAndAfter, { - cwd: exec.cwd('skipping-snapshot'), + cwd: cwd('skipping-snapshot'), cli: ['--update-snapshots'], expectChanged: false } @@ -16,7 +18,7 @@ test.serial( 'With --update-snapshots and t.snapshot.skip(), other snapshots are updated', beforeAndAfter, { - cwd: exec.cwd('skipping-snapshot-update'), + cwd: cwd('skipping-snapshot-update'), cli: ['--update-snapshots'], expectChanged: true } @@ -26,7 +28,7 @@ test.serial( 'With --update-snapshots, skipping tests preserves their data', beforeAndAfter, { - cwd: exec.cwd('skipping-test'), + cwd: cwd('skipping-test'), cli: ['--update-snapshots'], expectChanged: false } @@ -36,7 +38,7 @@ test.serial( 'With --update snapshots and test.skip(), other tests\' snapshots are updated', beforeAndAfter, { - cwd: exec.cwd('skipping-test-update'), + cwd: cwd('skipping-test-update'), cli: ['--update-snapshots'], expectChanged: true } @@ -46,7 +48,7 @@ test.serial( 'With --update-snapshots and --match, only selected tests are updated', beforeAndAfter, { - cwd: exec.cwd('select-test-update'), + cwd: cwd('select-test-update'), cli: ['--update-snapshots', '--match', 'foo'], expectChanged: true } @@ -56,7 +58,7 @@ test.serial( 'With --update-snapshots and line number selection, only selected tests are updated', beforeAndAfter, { - cwd: exec.cwd('select-test-update'), + cwd: cwd('select-test-update'), cli: ['--update-snapshots', 'test.js:3-5'], expectChanged: true } diff --git a/test/snapshot-workflow/try-skip.js b/test/snapshot-workflow/try-skip.js index 5acb96fd7..5b6cef921 100644 --- a/test/snapshot-workflow/try-skip.js +++ b/test/snapshot-workflow/try-skip.js @@ -1,12 +1,14 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); -const {beforeAndAfter} = require('./helpers/macros'); +import test from '@ava/test'; + +import {cwd} from '../helpers/exec.js'; + +import {beforeAndAfter} from './helpers/macros.js'; test.serial( 't.snapshot.skip() in discarded t.try() doesn\'t copy over old value', beforeAndAfter, { - cwd: exec.cwd('discard-skip'), + cwd: cwd('discard-skip'), cli: ['--update-snapshots'], expectChanged: true } @@ -16,7 +18,7 @@ test.serial( 't.snapshot.skip() in committed t.try() does copy over old value', beforeAndAfter, { - cwd: exec.cwd('commit-skip'), + cwd: cwd('commit-skip'), cli: ['--update-snapshots'], expectChanged: false } diff --git a/test/test-timeouts/fixtures/custom-message.js b/test/test-timeouts/fixtures/custom-message.js index f0ba01a76..48f80112e 100644 --- a/test/test-timeouts/fixtures/custom-message.js +++ b/test/test-timeouts/fixtures/custom-message.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('timeout with custom message', async t => { t.timeout(10, 'time budget exceeded'); diff --git a/test/test-timeouts/fixtures/invalid-message.js b/test/test-timeouts/fixtures/invalid-message.js index 3875ef0d1..0e0ae5f96 100644 --- a/test/test-timeouts/fixtures/invalid-message.js +++ b/test/test-timeouts/fixtures/invalid-message.js @@ -1,4 +1,4 @@ -const test = require('ava'); +import test from 'ava'; test('timeout with invalid message', t => { t.timeout(10, 20); // eslint-disable-line ava/assertion-arguments diff --git a/test/test-timeouts/fixtures/package.json b/test/test-timeouts/fixtures/package.json index f9b9cb835..54f672450 100644 --- a/test/test-timeouts/fixtures/package.json +++ b/test/test-timeouts/fixtures/package.json @@ -1,7 +1,8 @@ { - "ava": { - "files": [ - "*.js" - ] - } + "type": "module", + "ava": { + "files": [ + "*.js" + ] + } } diff --git a/test/test-timeouts/test.js b/test/test-timeouts/test.js index 2fdd67e2d..e63a876e6 100644 --- a/test/test-timeouts/test.js +++ b/test/test-timeouts/test.js @@ -1,14 +1,15 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('timeout message can be specified', async t => { - const result = await t.throwsAsync(exec.fixture(['custom-message.js'])); + const result = await t.throwsAsync(fixture(['custom-message.js'])); const error = result.stats.getError(result.stats.failed[0]); t.is(error.message, 'time budget exceeded'); }); test('timeout messages must be strings', async t => { - const result = await t.throwsAsync(exec.fixture(['invalid-message.js'])); + const result = await t.throwsAsync(fixture(['invalid-message.js'])); const error = result.stats.getError(result.stats.failed[0]); t.snapshot(error.message, 'error message'); t.snapshot(error.values, 'formatted values'); diff --git a/test/worker-threads/fixtures/package.json b/test/worker-threads/fixtures/package.json index 0967ef424..bedb411a9 100644 --- a/test/worker-threads/fixtures/package.json +++ b/test/worker-threads/fixtures/package.json @@ -1 +1,3 @@ -{} +{ + "type": "module" +} diff --git a/test/worker-threads/fixtures/test.js b/test/worker-threads/fixtures/test.js index ba548f588..1261130bb 100644 --- a/test/worker-threads/fixtures/test.js +++ b/test/worker-threads/fixtures/test.js @@ -1,5 +1,6 @@ -const {isMainThread} = require('worker_threads'); -const test = require('ava'); +import {isMainThread} from 'worker_threads'; + +import test from 'ava'; test('in worker thread', t => { t.false(isMainThread); diff --git a/test/worker-threads/test.js b/test/worker-threads/test.js index 2cda7b198..d600b0fce 100644 --- a/test/worker-threads/test.js +++ b/test/worker-threads/test.js @@ -1,17 +1,18 @@ -const test = require('@ava/test'); -const exec = require('../helpers/exec'); +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; test('run in worker thread by default', async t => { - const result = await exec.fixture([]); + const result = await fixture([]); t.is(result.stats.passed.length, 1); }); test('--no-worker-threads causes tests to run in a child process', async t => { - const result = await t.throwsAsync(exec.fixture(['--no-worker-threads'])); + const result = await t.throwsAsync(fixture(['--no-worker-threads'])); t.is(result.stats.failed.length, 1); }); test('`workerThreads: false` configuration causes tests to run in a child process', async t => { - const result = await t.throwsAsync(exec.fixture(['--config=child-process.config.mjs'])); + const result = await t.throwsAsync(fixture(['--config=child-process.config.mjs'])); t.is(result.stats.failed.length, 1); }); diff --git a/xo.config.js b/xo.config.js deleted file mode 100644 index 701d5ffdb..000000000 --- a/xo.config.js +++ /dev/null @@ -1,69 +0,0 @@ -module.exports = { - ignores: [ - 'media/**', - 'test/config/fixtures/config-errors/test.js', - 'test/config/fixtures/mjs-with-tests/**', - 'test-tap/fixture/ava-paths/target/test.js', - 'test-tap/fixture/{source-map-initial,syntax-error}.js', - 'test-tap/fixture/snapshots/test-sourcemaps/build/**', - 'test-tap/fixture/power-assert.js', - 'test-tap/fixture/report/edgecases/ast-syntax-error.js' - ], - rules: { - 'import/extensions': ['error', {js: 'never'}], - 'import/no-anonymous-default-export': 'off', - 'import/no-unresolved': ['error', {commonjs: true}], - 'no-use-extend-native/no-use-extend-native': 'off', - '@typescript-eslint/no-var-requires': 'off' - }, - overrides: [ - { - files: 'index.d.ts', - rules: { - '@typescript-eslint/member-ordering': 'off', - '@typescript-eslint/method-signature-style': 'off', - '@typescript-eslint/prefer-readonly-parameter-types': 'off', - '@typescript-eslint/prefer-function-type': 'off', - '@typescript-eslint/unified-signatures': 'off' - } - }, - { - files: 'test-{d,tap}/**/*.ts', - rules: { - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/no-unsafe-member-access': 'off', - '@typescript-eslint/no-unsafe-return': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/prefer-readonly-parameter-types': 'off', - 'no-unused-vars': 'off' - } - }, - { - // Little point modernizing these legacy test files. - files: 'test-tap/**/*.js', - rules: { - 'promise/prefer-await-to-then': 'off', - 'unicorn/error-message': 'off', - 'unicorn/no-array-reduce': 'off', - 'unicorn/prevent-abbreviations': 'off' - } - }, - { - files: ['test-tap/fixture/**', 'test/**/fixtures/**'], - rules: { - 'ava/no-todo-test': 'off', - 'import/no-extraneous-dependencies': 'off', - 'import/no-unresolved': 'off' - } - } - ], - settings: { - 'import/resolver': { - node: { - extensions: ['.js'] - } - } - } -};