babel-plugin-tester
Version:
Utilities for testing babel plugins
73 lines (72 loc) • 6.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ErrorMessage = void 0;
var _nodeUtil = require("node:util");
var _constant = require("./constant.js");
const {
isNativeError
} = _nodeUtil.types;
const ErrorMessage = exports.ErrorMessage = {
TestEnvironmentUndefinedDescribe: () => 'incompatible testing environment: testing environment must define `describe` in its global scope',
TestEnvironmentUndefinedIt: () => 'incompatible testing environment: testing environment must define `it` in its global scope',
TestEnvironmentNoSnapshotSupport: () => 'testing environment does not support `expect(...).toMatchSnapshot` method',
TestEnvironmentNoSkipSupport: () => 'testing environment does not support `it.skip(...)` method',
TestEnvironmentNoOnlySupport: () => 'testing environment does not support `it.only(...)` method',
BadConfigPluginAndPreset: () => 'failed to validate configuration: cannot test a plugin and a preset simultaneously. Specify one set of options or the other',
BadConfigNoPluginOrPreset: () => 'failed to validate configuration: must provide either `plugin` or `preset` option',
BadConfigInvalidTitleNumbering: () => 'failed to validate configuration: invalid `titleNumbering` option',
BadConfigFixturesNotString: () => 'failed to validate configuration: `fixtures`, if defined, must be a string',
BadConfigInvalidTestsType: () => 'failed to validate configuration: `tests`, if defined, must be an array or an object',
BadConfigInvalidTestsArrayItemType: index => `failed to validate configuration: \`tests\` array item at index ${index} must be a string, TestObject, or nullish`,
BadConfigInvalidTestsObjectProperty: title => `failed to validate configuration: \`tests\` object property "${title}" must have a value of type string, TestObject, or nullish`,
BadConfigInvalidEndOfLine: endOfLine => `failed to validate configuration: invalid \`endOfLine\` option "${String(endOfLine)}"`,
BadEnvironmentVariableRange: (name, rangeStr, range) => `invalid environment variable "${name}": invalid range ${rangeStr}` + (range ? `: ${range.start} is greater than ${range.end}` : ''),
SetupFunctionFailed: error => `setup function failed: ${String(isNativeError(error) ? error.message : error)}`,
TeardownFunctionFailed: (functionError, frameworkError) => {
const frameworkErrorMessage = frameworkError ? `\n\nAdditionally, the testing framework reported the following error: ${String(isNativeError(frameworkError) ? frameworkError.message : frameworkError)}` : '';
return `teardown function failed: ${String(isNativeError(functionError) ? functionError.message : functionError)}${frameworkErrorMessage}`;
},
ExpectedBabelToThrow: () => 'expected babel to throw an error, but it did not',
ExpectedErrorToBeInstanceOf: expectedError => `expected error to be an instance of ${expectedError.name || 'the expected error'}`,
ExpectedThrowsFunctionToReturnTrue: () => 'expected `throws`/`error` function to return true',
ExpectedErrorToIncludeString: (resultString, expectedError) => `expected "${resultString}" to include "${expectedError}"`,
ExpectedErrorToMatchRegExp: (resultString, expectedError) => `expected "${resultString}" to match ${String(expectedError)}`,
BabelOutputTypeIsNotString: rawBabelOutput => `unexpected babel output of type "${typeof rawBabelOutput}" (expected 'code' property to be of type "string")`,
BabelOutputUnexpectedlyEmpty: () => 'attempted to execute babel output but it was empty. An empty string cannot be evaluated',
AttemptedToSnapshotUnmodifiedBabelOutput: () => 'code was unmodified but attempted to take a snapshot. If the code should not be modified, set `snapshot: false`',
ExpectedOutputToEqualActual: testConfig => {
return `actual output does not match ${String(testConfig[_constant.$type] === 'fixture-object' ? testConfig.fixtureOutputBasename : 'expected output')}`;
},
ExpectedOutputNotToChange: () => 'expected output not to change, but it did',
ValidationFailed: (title, message) => `failed to validate configuration for test "${title}": ${message}`,
InvalidHasCodeAndCodeFixture: () => '`code` cannot be provided with `codeFixture` or `fixture`',
InvalidHasOutputAndOutputFixture: () => '`output` cannot be provided with `outputFixture`',
InvalidHasExecAndExecFixture: () => '`exec` cannot be provided with `execFixture`',
InvalidHasSnapshotAndOutput: () => 'neither `output` nor `outputFixture` can be provided with `snapshot` enabled',
InvalidHasSnapshotAndExec: () => 'neither `exec` nor `execFixture` can be provided with `snapshot` enabled',
InvalidHasSnapshotAndThrows: () => 'neither `throws` nor `error` can be provided with `snapshot` enabled',
InvalidHasSkipAndOnly: () => 'cannot enable both `skip` and `only` in the same test',
InvalidHasThrowsAndOutput: testConfig => {
return testConfig[_constant.$type] === 'test-object' ? 'neither `output` nor `outputFixture` can be provided with `throws` or `error`' : 'a fixture cannot be provided with `throws` or `error` and also contain an output file';
},
InvalidHasThrowsAndOutputRaw: () => '`outputRaw` cannot be provided with `throws` or `error`',
InvalidHasThrowsAndExec: testConfig => {
return testConfig[_constant.$type] === 'test-object' ? 'neither `exec` nor `execFixture` can be provided with `throws` or `error`' : 'a fixture cannot be provided with `throws` or `error` and also contain an exec file';
},
InvalidMissingCodeOrExec: testConfig => {
return testConfig[_constant.$type] === 'test-object' ? 'a string or object with a `code`, `codeFixture`, `fixture`, `exec`, or `execFixture` must be provided' : 'a fixture must contain either a code file or an exec file';
},
InvalidHasExecAndCodeOrOutput: testConfig => {
return testConfig[_constant.$type] === 'test-object' ? 'neither `code`, `codeFixture`, `fixture`, `output`, nor `outputFixture` can be provided with `exec` or `execFixture`' : 'a fixture cannot contain both an exec file and a code or output file';
},
InvalidHasBabelrcButNoFilename: () => '`babelOptions.babelrc` is enabled but `babelOptions.filename` was not provided',
InvalidThrowsType: () => '`throws`/`error` must be a function, string, boolean, RegExp, or Error subtype',
GenericErrorWithPath: (error, path) => {
const message = String(isNativeError(error) ? error.message : error);
return !path || message.includes(path) ? message : `${path}: ${message}`;
},
PathIsNotAbsolute: path => `"${path}" is not an absolute path`,
UnableToDeriveAbsolutePath: (filepath, filepathName, basename, basenameName) => `unable to derive an absolute path from the provided ${filepathName} and ${basenameName}:\n\n${filepathName}: ${String(filepath)}\n${basenameName}: ${String(basename)}`
};