@storm-software/testing-tools
Version:
A package containing various testing tools used by Storm workspaces to drive unit and e2e testing.
163 lines (158 loc) • 6.33 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
declarePackage: () => declarePackage,
declarePreset: () => declarePreset,
declareWorkspace: () => declareWorkspace
});
module.exports = __toCommonJS(index_exports);
// src/jest/declare-package.ts
var import_mlly = require("mlly");
var import_node_path = require("path");
function declarePackage(options) {
return {
displayName: options.displayName ? options.displayName : options.projectRoot.replaceAll("\\", "-").replaceAll("/", "-"),
preset: (0, import_mlly.resolvePathSync)("@storm-software/testing-tools/jest/preset"),
testEnvironment: options.isNode ? "node" : "jsdom",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: (0, import_node_path.join)("<rootDir>/coverage", options.projectRoot)
};
}
// src/jest/declare-preset.ts
var import_preset = __toESM(require("@nx/jest/preset"), 1);
var import_defu = __toESM(require("defu"), 1);
function declarePreset(config = {}) {
return (0, import_defu.default)(
config,
{
collectCoverage: true,
testTimeout: 3e4,
clearMocks: true,
testMatch: ["**/+(*.)+(spec|test).+(ts|js)?(x)"],
transform: {
"^.+\\.(ts|js|mts|mjs|cts|cjs|html)$": [
"ts-jest",
{ tsconfig: "<rootDir>/tsconfig.spec.json" }
]
},
snapshotFormat: {
printBasicPrototype: false
},
globals: {
"ts-jest": {
isolatedModules: true,
diagnostics: {
exclude: ["**"]
}
}
},
moduleFileExtensions: ["ts", "js", "html"],
coverageReporters: [
"json",
"lcov",
"text",
"clover",
"text-summary",
"html"
],
maxWorkers: 1
},
import_preset.default ?? {}
);
}
// src/jest/declare-workspace.ts
var import_jest = require("@nx/jest");
var import_defu2 = __toESM(require("defu"), 1);
function declareWorkspace(config = {}) {
return async () => (0, import_defu2.default)(config, {
/**
* When the projects configuration is provided with an array of paths or glob patterns, Jest will run tests in all of the specified projects at the same time.
* This is great for monorepos or when working on multiple projects at the same time.
*/
projects: [...await (0, import_jest.getJestProjectsAsync)(), "<rootDir>/jest.config.ts"],
/**
* Indicates whether the coverage information should be collected while executing the test. Because this retrofits all
* executed files with coverage collection statements, it may significantly slow down your tests. Default: false
*/
collectCoverage: process.env.CI ? true : false,
/**
* An array of glob patterns indicating a set of files for which coverage information should be collected.
* If a file matches the specified glob pattern, coverage information will be collected for it even if no tests exist
* for this file and it's never required in the test suite. Default: undefined
*/
// collectCoverageFrom: ["**/*(!*.spec).tsx", "**/*(!*.spec).ts"],
/**
* The directory where Jest should output its coverage files. Default: undefined
*/
coverageDirectory: "<rootDir>/coverage",
/**
* An array of regexp pattern strings that are matched against all file paths before executing the test. If the file path
* matches any of the patterns, coverage information will be skipped.
*/
coveragePathIgnorePatterns: [
"\\.spec\\.ts$",
"\\.test\\.ts$",
"<rootDir>/dist",
"<rootDir>/tests",
"<rootDir>/__generated__",
"<rootDir>/node_modules"
],
/**
* The test environment that will be used for testing. The default environment in Jest is a Node.js environment.
* If you are building a web app, you can use a browser-like environment through jsdom instead.
*/
testEnvironment: "jest-environment-jsdom",
/**
* A list of reporter names that Jest uses when writing coverage reports. Any istanbul reporter can be used.
* Default: ["json", "lcov", "text"]
*/
coverageReporters: ["lcov", "json"],
/**
* Setup files that run before each test suite.
*
* @remarks
* This is useful for setting up global variables or configurations that your tests need.
*/
setupFiles: ["./node_modules/@storm-software/testing-tools/jest/setup"],
moduleNameMapper: {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "@storm-software/testing-tools/jest/__mocks__/file.mock.js",
"\\.(css|less)$": "@storm-software/testing-tools/jest/__mocks__/style.mock.js"
}
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
declarePackage,
declarePreset,
declareWorkspace
});