From 3e5a70fc5b0c9a53db5c6927eaf5a9e7bb436716 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 11 Jan 2025 16:39:37 +0100 Subject: [PATCH] Converted specs to esm --- jest.config.cjs => jest.config.mjs | 4 ++-- package.json | 2 +- specs/{PKPass.spec.cjs => PKPass.spec.mjs} | 19 ++++++++----------- specs/{utils.spec.cjs => utils.spec.mjs} | 4 ++-- 4 files changed, 13 insertions(+), 16 deletions(-) rename jest.config.cjs => jest.config.mjs (72%) rename specs/{PKPass.spec.cjs => PKPass.spec.mjs} (99%) rename specs/{utils.spec.cjs => utils.spec.mjs} (88%) diff --git a/jest.config.cjs b/jest.config.mjs similarity index 72% rename from jest.config.cjs rename to jest.config.mjs index 435e03b..25e4f78 100644 --- a/jest.config.cjs +++ b/jest.config.mjs @@ -4,9 +4,9 @@ * @type {import("jest").Config} */ -module.exports = { +export default { moduleFileExtensions: ["js", "mjs", "cjs"], testEnvironment: "node", - testMatch: ["**/specs/**/*.spec.cjs"], + testMatch: ["**/specs/**/*.spec.mjs"], injectGlobals: false, }; diff --git a/package.json b/package.json index f2b676f..c4adf16 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build:dual": "pnpm tsconfig-to-dual-package tsconfig.esm.json tsconfig.cjs.json", "build:all": "pnpm build && pnpm build:examples", "prepublishOnly": "pnpm build && pnpm test", - "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" pnpm jest -c jest.config.cjs --silent" + "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" pnpm jest -c jest.config.mjs --silent" }, "author": "Alexander Patrick Cerutti", "license": "MIT", diff --git a/specs/PKPass.spec.cjs b/specs/PKPass.spec.mjs similarity index 99% rename from specs/PKPass.spec.cjs rename to specs/PKPass.spec.mjs index 195ed79..29f0748 100644 --- a/specs/PKPass.spec.cjs +++ b/specs/PKPass.spec.mjs @@ -1,15 +1,12 @@ // @ts-check -const { - beforeEach, - beforeAll, - expect, - it, - describe, -} = require("@jest/globals"); -const fs = require("node:fs"); -const path = require("node:path"); -const forge = require("node-forge"); -const { default: PKPass } = require("../lib/PKPass"); +import { beforeEach, beforeAll, expect, it, describe } from "@jest/globals"; +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import forge from "node-forge"; +import { PKPass } from "passkit-generator"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * @returns {[cert: Buffer, key: Buffer]} diff --git a/specs/utils.spec.cjs b/specs/utils.spec.mjs similarity index 88% rename from specs/utils.spec.cjs rename to specs/utils.spec.mjs index 9a5ad3e..d6c30e6 100644 --- a/specs/utils.spec.cjs +++ b/specs/utils.spec.mjs @@ -1,5 +1,5 @@ -const { describe, expect, it } = require("@jest/globals"); -const { processDate, removeHidden } = require("../lib/utils"); +import { describe, expect, it } from "@jest/globals"; +import { processDate, removeHidden } from "../lib/esm/utils.js"; describe("Utils", () => { describe("removeHidden", () => {