From 8754f02c9265faaeb745e3eed276a73c1a250959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Sat, 18 Sep 2021 00:11:00 +0200 Subject: [PATCH] test: add cjs tests --- jest.config.cjs.ts | 23 +++++++++++++++++++++++ jest.config.ts => jest.config.esm.ts | 0 package.json | 3 ++- src/locate.test.ts | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 jest.config.cjs.ts rename jest.config.ts => jest.config.esm.ts (100%) diff --git a/jest.config.cjs.ts b/jest.config.cjs.ts new file mode 100644 index 0000000..a441dec --- /dev/null +++ b/jest.config.cjs.ts @@ -0,0 +1,23 @@ +import type { Config } from '@jest/types' + +// see https://jestjs.io/docs/ecmascript-modules + +// Sync object +const config: Config.InitialOptions = { + verbose: true, + testMatch: [ + '**/__tests__/**/*.+(ts|tsx|js)', + '**/?(*.)+(spec|test).+(ts|tsx|js)', + ], + moduleDirectories: [ + 'node_modules', + 'src', + ], + moduleFileExtensions: ['ts', 'js'], + extensionsToTreatAsEsm: ['.ts'], + transform: { + '^.+\\.ts$': 'ts-jest', + }, +} + +export default config diff --git a/jest.config.ts b/jest.config.esm.ts similarity index 100% rename from jest.config.ts rename to jest.config.esm.ts diff --git a/package.json b/package.json index 6ef8d1f..5785364 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "bugs": "https://github.com/iconify/collections-json/issues", "scripts": { "build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts", - "test": "yarn build && jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest" + "test-esm": "yarn build && jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.config.esm.ts", + "test-cjs": "yarn build && jest --clearCache && jest --config=jest.config.cjs.ts" }, "dependencies": { "upath": "^2.0.1" diff --git a/src/locate.test.ts b/src/locate.test.ts index 38df4b9..fbc223a 100644 --- a/src/locate.test.ts +++ b/src/locate.test.ts @@ -6,7 +6,7 @@ const cwd = process.cwd() describe('locate', () => { test('mdi resolves the json collection', () => { const received = locate('mdi') as string - const expected = resolve(cwd, 'json/', 'mdi.json').replace(/\\/g, '/') + const expected = resolve(cwd, 'json', 'mdi.json').replace(/\\/g, '/') expect(received).toBe(expected) }) })