Skip to content

Commit

Permalink
Restore index module
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonAlling committed Jul 31, 2024
1 parent 3ff028a commit d212b06
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
23 changes: 19 additions & 4 deletions __tests__/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as packageJson from "../package.json";
import * as fs from "fs";
import * as path from "path";

import * as index from "../src/run-time";
import * as environment from "../src/run-time/environment";
import * as errors from "../src/run-time/errors";
import * as operations from "../src/run-time/operations";
Expand All @@ -24,7 +27,19 @@ it("exposes the intended API", () => {
expect(stylesheets.disable).toBeDefined();
});

it("exposes everything in run-time/", () => {
expect(packageJson.exports["./run-time/*"]).toEqual({ import: "./run-time/*.mjs", require: "./run-time/*.js" });
expect(packageJson.typesVersions["*"]["run-time/*"]).toEqual([ "./run-time/*.d.ts" ]);
it("exposes everything in run-time in index.ts", async () => {
const filenames = await fs.promises.readdir(path.resolve(__dirname, "..", "src", "run-time"));
expect(filenames).toEqual([
"environment.ts",
"errors.ts",
"index.ts",
"log.ts",
"operations.ts",
"preferences.ts",
"stylesheets.ts",
"userscripter.ts",
]);
const modulesThatAreExported = Object.keys(index);
const modulesThatShouldBeExported = filenames.map(n => n.replace(/\.ts$/, "")).filter(n => n !== "index");
expect(modulesThatAreExported).toEqual(modulesThatShouldBeExported);
});
8 changes: 4 additions & 4 deletions __tests__/operations.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { operations } from "../src/run-time";
import {
ALWAYS,
DOMCONTENTLOADED,
Expand All @@ -7,7 +8,6 @@ import {
Operation,
OperationAndFailure,
operation,
run,
} from "../src/run-time/operations";

const mockConsole = {
Expand Down Expand Up @@ -108,7 +108,7 @@ const OPERATIONS_BLABLABLA = [

it("can run operations", () => {
document.documentElement.innerHTML = HTML_EXAMPLE;
run({
operations.run({
...PLAN,
operations: OPERATIONS,
});
Expand All @@ -117,7 +117,7 @@ it("can run operations", () => {

it("can log " + BLABLABLA, () => {
document.documentElement.innerHTML = HTML_WITH_BLABLABLA;
run({
operations.run({
...PLAN,
operations: OPERATIONS_BLABLABLA,
});
Expand All @@ -127,7 +127,7 @@ it("can log " + BLABLABLA, () => {

it("can handle an internal failure", () => {
document.documentElement.innerHTML = HTML_WITHOUT_BLABLABLA;
run({
operations.run({
...PLAN,
operations: OPERATIONS_BLABLABLA,
});
Expand Down
9 changes: 1 addition & 8 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
export default {
"testEnvironment": "jsdom",
"transform": {
"^.+\\.ts$": [
"ts-jest",
{
tsconfig: {
resolveJsonModule: true,
},
},
],
"^.+\\.ts$": "ts-jest",
},
"testRegex": ".+\\.test\\.ts$",
"moduleFileExtensions": [
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
"bugs": {
"url": "https://github.com/simonalling/userscripter/issues"
},
"main": "run-time/index",
"exports": {
".": {
"import": "./run-time/index.mjs",
"require": "./run-time/index.js"
},
"./build-time": {
"import": "./build-time/index.mjs",
"require": "./build-time/index.js"
Expand Down
17 changes: 17 additions & 0 deletions src/run-time/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as environment from "./environment";
import * as errors from "./errors";
import * as log from "./log";
import * as operations from "./operations";
import * as preferences from "./preferences";
import * as stylesheets from "./stylesheets";
import * as userscripter from "./userscripter";

export {
environment,
errors,
log,
operations,
preferences,
stylesheets,
userscripter,
};

0 comments on commit d212b06

Please sign in to comment.