diff --git a/jest.cjs.config.ts b/jest.cjs.config.ts new file mode 100644 index 0000000..734df2a --- /dev/null +++ b/jest.cjs.config.ts @@ -0,0 +1,7 @@ +import config from './jest/jest.shared.config' + +config.testMatch = [ + '**/?(*.)+(cjs).+(spec|test).+(ts|tsx|js)', +] + +export default config diff --git a/jest.config.esm.ts b/jest.config.esm.ts deleted file mode 100644 index 7e463ce..0000000 --- a/jest.config.esm.ts +++ /dev/null @@ -1,9 +0,0 @@ -import config from './jest.config.cjs' - -config.globals = { - 'ts-jest': { - useESM: true, - }, -} - -export default config diff --git a/jest.esm.config.ts b/jest.esm.config.ts new file mode 100644 index 0000000..c013a2e --- /dev/null +++ b/jest.esm.config.ts @@ -0,0 +1,12 @@ +import config from './jest/jest.shared.config' + +config.testMatch = [ + '**/?(*.)+(esm).+(spec|test).+(ts|tsx|js)', +] +config.globals = { + 'ts-jest': { + useESM: true, + }, +} + +export default config diff --git a/jest.config.cjs.ts b/jest/jest.shared.config.ts similarity index 78% rename from jest.config.cjs.ts rename to jest/jest.shared.config.ts index a441dec..4fc8545 100644 --- a/jest.config.cjs.ts +++ b/jest/jest.shared.config.ts @@ -5,10 +5,6 @@ import type { Config } from '@jest/types' // Sync object const config: Config.InitialOptions = { verbose: true, - testMatch: [ - '**/__tests__/**/*.+(ts|tsx|js)', - '**/?(*.)+(spec|test).+(ts|tsx|js)', - ], moduleDirectories: [ 'node_modules', 'src', diff --git a/package.json b/package.json index 5785364..9d5ba2b 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,21 @@ { "name": "@iconify/json", - "description": "Iconify icons collection in JSON format", - "license": "MIT", "version": "1.1.401", + "description": "Iconify icons collection in JSON format", + "homepage": "https://iconify.design/icon-sets/", + "bugs": "https://github.com/iconify/collections-json/issues", "repository": { "type": "git", "url": "git+ssh://git@github.com/iconify/collections-json.git" }, - "files": [ + "license": "MIT", + "exports": { + ".": { + "require": "./dist/index.js", + "import": "./dist/index.mjs" + } + }, + "files": [ "dist", "json", "lib", @@ -19,12 +27,10 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", - "homepage": "https://iconify.design/icon-sets/", - "bugs": "https://github.com/iconify/collections-json/issues", "scripts": { "build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts", - "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" + "test-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts", + "test-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts" }, "dependencies": { "upath": "^2.0.1" diff --git a/src/index.ts b/src/index.ts index 7c185ee..20681d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,9 @@ */ import { PathLike, promises as fs } from 'fs' import { fileURLToPath } from 'url' -import { dirname, resolve } from 'upath' +import Upath from 'upath' + +const { dirname, resolve } = Upath /** * Icon dimensions. diff --git a/src/loadCollection.test.ts b/src/loadCollection.cjs.test.ts similarity index 100% rename from src/loadCollection.test.ts rename to src/loadCollection.cjs.test.ts diff --git a/src/loadCollection.esm.test.ts b/src/loadCollection.esm.test.ts new file mode 100644 index 0000000..4a7ced9 --- /dev/null +++ b/src/loadCollection.esm.test.ts @@ -0,0 +1,27 @@ +import { IconifyMetaDataCollection, lookupCollection, lookupCollections } from '.' + +let collections: IconifyMetaDataCollection + +describe('lookupCollection and lookupCollections', () => { + beforeAll(() => { + return lookupCollections().then((c) => { + collections = c + return Promise.resolve(c) + }) + }) + test('lookupCollections has data', () => { + expect(collections ? Object.keys(collections).length : 0).toBeGreaterThan(0) + }) + test('mdi collection has prefix mdi', async() => { + const collection = await lookupCollection('mdi') + expect(collection.prefix).toBe('mdi') + }) + test('websymbol collection has prefix websymbol', async() => { + const collection = await lookupCollection('websymbol') + expect(collection.prefix).toBe('websymbol') + }) + test('fa collection has prefix fa', async() => { + const collection = await lookupCollection('fa') + expect(collection.prefix).toBe('fa') + }) +}) diff --git a/src/locate.test.ts b/src/locate.cjs.test.ts similarity index 100% rename from src/locate.test.ts rename to src/locate.cjs.test.ts diff --git a/src/locate.esm.test.ts b/src/locate.esm.test.ts new file mode 100644 index 0000000..b63769c --- /dev/null +++ b/src/locate.esm.test.ts @@ -0,0 +1,10 @@ +import { resolve } from 'path' +import { locate } from '.' + +const cwd = process.cwd() + +test('mdi resolves the json collection', () => { + const received = locate('mdi') as string + const expected = resolve(cwd, 'json', 'mdi.json').replace(/\\/g, '/') + expect(received).toBe(expected) +}) diff --git a/tsconfig.json b/tsconfig.json index b8a4767..685e220 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "baseUrl": ".", - "module": "ESNext", + "module": "esnext", "target": "ESNext", "lib": ["ESNext"], "esModuleInterop": true,