Skip to content

Commit

Permalink
- partial fix for unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezolenko committed May 18, 2023
1 parent 1f95797 commit 966ba74
Show file tree
Hide file tree
Showing 5 changed files with 11,295 additions and 5,208 deletions.
8 changes: 4 additions & 4 deletions __tests__/context.spec.ts
@@ -1,7 +1,7 @@
import { jest, test, expect } from "@jest/globals";

import { makeContext } from "./fixtures/context";
import { RollupContext } from "../src/context";
import { RollupContext, VerbosityLevel } from "../src/context";

(global as any).console = {
warn: jest.fn(),
Expand All @@ -11,7 +11,7 @@ import { RollupContext } from "../src/context";

test("RollupContext", () => {
const innerContext = makeContext();
const context = new RollupContext(5, false, innerContext);
const context = new RollupContext(VerbosityLevel.Debug + 1, false, innerContext);

context.warn("test");
expect(innerContext.warn).toHaveBeenLastCalledWith("test");
Expand Down Expand Up @@ -52,7 +52,7 @@ test("RollupContext with 0 verbosity", () => {

test("RollupContext.error + debug negative verbosity", () => {
const innerContext = makeContext();
const context = new RollupContext(-100, true, innerContext);
const context = new RollupContext(VerbosityLevel.Error - 1, true, innerContext);

context.error("verbosity is too low here");
expect(innerContext.error).not.toBeCalled();
Expand All @@ -62,7 +62,7 @@ test("RollupContext.error + debug negative verbosity", () => {

test("RollupContext.error with bail", () => {
const innerContext = makeContext();
const context = new RollupContext(5, true, innerContext);
const context = new RollupContext(VerbosityLevel.Debug, true, innerContext);

context.error("bail");
expect(innerContext.error).toHaveBeenLastCalledWith("bail");
Expand Down
10 changes: 0 additions & 10 deletions __tests__/integration/helpers.ts
Expand Up @@ -35,16 +35,6 @@ export async function genBundle (inputArgs: Params) {
const bundle = await rollup(createInput(inputArgs));
const esm = await bundle.generate(createOutput(inputArgs.testDir));

// Rollup has some deprecated properties like `get isAsset`, so enumerating them with, e.g. `.toEqual`, causes a bunch of warnings to be output
// delete the `isAsset` property for (much) cleaner logs
const { output: files } = esm;
for (const file of files) {
if ("isAsset" in file) {
const optIsAsset = file as Partial<Pick<OutputAsset, "isAsset">> & Omit<OutputAsset, "isAsset">;
delete optIsAsset["isAsset"];
}
}

return esm;
}

Expand Down
11 changes: 7 additions & 4 deletions jest.config.js
Expand Up @@ -3,16 +3,18 @@ const pkg = require("./package.json");
/** @type {import("ts-jest").InitialOptionsTsJest} */
const config = {
// ts-jest settings
preset: "ts-jest",
preset: "ts-jest/presets/js-with-ts",
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
// other globals (unrelated to ts-jest) -- these are namespaced so they don't conflict with anything else
"rpt2__TS_VERSION_RANGE": pkg.peerDependencies.typescript,
"rpt2__ROLLUP_VERSION_RANGE": pkg.peerDependencies.rollup,
"rpt2__RPT2_VERSION": pkg.version,
},
transform: {
"<rootdir>/__tests__/*.ts": ["ts-jest", {
tsconfig: "./tsconfig.test.json",
}],
},

// jest settings
injectGlobals: false, // use @jest/globals instead
Expand All @@ -23,6 +25,7 @@ const config = {
"node_modules", // default
"<rootDir>/__tests__/" // ignore any test helper files
],
moduleDirectories: ["node_modules", "<rootdir>/src/"],
};

module.exports = config;

0 comments on commit 966ba74

Please sign in to comment.