2
0
mirror of https://github.com/iconify/collections-json.git synced 2024-09-16 17:19:03 +00:00

test: hacking cjs tests

chore: modify target and module on tsconfig configuration
This commit is contained in:
Joaquín Sánchez Jiménez 2021-09-18 14:42:03 +02:00
parent 233e4ddcfd
commit 08c5ce10f7
11 changed files with 91 additions and 102 deletions

View File

@ -1,7 +1,12 @@
import config from './jest/jest.shared.config' import { buildConfiguration } from './jest/jest.shared.config'
config.testMatch = [ export default buildConfiguration({
'**/?(*.)+(cjs).+(spec|test).+(ts|tsx|js)', testMatch: [
] '**/?(*.)+(cjs).+(spec|test).+(ts|tsx|js)',
],
export default config globals: {
'ts-jest': {
useESM: false,
},
},
})

View File

@ -1,12 +1,12 @@
import config from './jest/jest.shared.config' import { buildConfiguration } from './jest/jest.shared.config'
config.testMatch = [ export default buildConfiguration({
'**/?(*.)+(esm).+(spec|test).+(ts|tsx|js)', testMatch: [
] '**/?(*.)+(esm).+(spec|test).+(ts|tsx|js)',
config.globals = { ],
'ts-jest': { globals: {
useESM: true, 'ts-jest': {
useESM: true,
},
}, },
} })
export default config

View File

@ -2,18 +2,17 @@ import type { Config } from '@jest/types'
// see https://jestjs.io/docs/ecmascript-modules // see https://jestjs.io/docs/ecmascript-modules
// Sync object export const buildConfiguration = (configuration: Partial<Config.InitialOptions>): Config.InitialOptions => {
const config: Config.InitialOptions = { return Object.assign({}, {
verbose: true, verbose: true,
moduleDirectories: [ moduleDirectories: [
'node_modules', 'node_modules',
'src', 'src',
], ],
moduleFileExtensions: ['ts', 'js'], moduleFileExtensions: ['ts', 'js'],
extensionsToTreatAsEsm: ['.ts'], extensionsToTreatAsEsm: ['.ts'],
transform: { transform: {
'^.+\\.ts$': 'ts-jest', '^.+\\.ts$': 'ts-jest',
}, },
}, configuration)
} }
export default config

View File

@ -15,7 +15,7 @@
"import": "./dist/index.mjs" "import": "./dist/index.mjs"
} }
}, },
"files": [ "files": [
"dist", "dist",
"json", "json",
"lib", "lib",

View File

@ -1,27 +1,4 @@
import { IconifyMetaDataCollection, lookupCollection, lookupCollections } from '../dist' import { lookupCollection, lookupCollections } from '../dist'
import { lookupCollectionTest } from './loadCollection.test'
let collections: IconifyMetaDataCollection lookupCollectionTest(lookupCollection, lookupCollections)
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')
})
})

View File

@ -1,27 +1,4 @@
import { IconifyMetaDataCollection, lookupCollection, lookupCollections } from '.' import { lookupCollectionTest } from './loadCollection.test'
import { lookupCollection, lookupCollections } from '.'
let collections: IconifyMetaDataCollection lookupCollectionTest(lookupCollection, lookupCollections)
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')
})
})

View File

@ -0,0 +1,32 @@
import type { IconifyMetaDataCollection } from '.'
import { IconifyJSON } from '.'
export const lookupCollectionTest = (
lookupCollection: (name: string) => Promise<IconifyJSON>,
lookupCollections: () => Promise<IconifyMetaDataCollection>,
) => {
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')
})
})
}

View File

@ -1,10 +1,4 @@
import { resolve } from 'path'
import { locate } from '../dist' import { locate } from '../dist'
import { locateTest } from './locate.test'
const cwd = process.cwd() locateTest(locate)
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)
})

View File

@ -1,10 +1,4 @@
import { resolve } from 'path' import { locateTest } from './locate.test'
import { locate } from '.' import { locate } from '.'
const cwd = process.cwd() locateTest(locate)
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)
})

12
src/locate.test.ts Normal file
View File

@ -0,0 +1,12 @@
import { resolve } from 'path'
import { PathLike } from 'fs'
const cwd = process.cwd()
export const locateTest = (locate: (name: string) => PathLike) => {
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)
})
}

View File

@ -1,8 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "target": "es2017",
"module": "esnext", "module": "ESNext",
"target": "ESNext",
"lib": ["ESNext"], "lib": ["ESNext"],
"esModuleInterop": true, "esModuleInterop": true,
"strict": true, "strict": true,