Skip to content

Commit

Permalink
common loader setup & teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 13, 2023
1 parent 6003742 commit 20437f3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 55 deletions.
16 changes: 2 additions & 14 deletions test/ingredient.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import { PackLoader } from '../src/index.js'
import createTestLogger from './mock/TestLogger.js'
import createTestResolver from './mock/TestResolver.js'
import createTestAcceptor from './mock/TestAcceptor.js'
import { createIngredient } from '../src/common/ingredient.js'
import { createResult } from '../src/common/result.js'
import { tryCatching } from '../src/error.js'
import setupLoader from './shared/loaderSetup'

Check failure on line 5 in test/ingredient.test.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js

const logger = createTestLogger()
const loader = new PackLoader(logger)
beforeAll(async () => {
const resolver = createTestResolver()
await loader.loadFrom(resolver)
}, 10_000)

afterEach(() => {
loader.clear()
logger.reset()
})
const { logger, loader } = setupLoader()

describe('tests regarding ingredient/result shapes', () => {
it('warns about unknown ingredient shape', async () => {
Expand Down
12 changes: 2 additions & 10 deletions test/loot.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import PackLoader from '../src/loader/pack.js'
import createTestLogger from './mock/TestLogger.js'
import createTestResolver from './mock/TestResolver.js'
import createTestAcceptor from './mock/TestAcceptor.js'
import { LootEntrySchema, LootTableSchema } from '../src/schema/loot.js'
import { EMPTY_LOOT_TABLE } from '../src/emit/loot.js'
import setupLoader from './shared/loaderSetup'

Check failure on line 4 in test/loot.test.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js

const logger = createTestLogger()
const loader = new PackLoader(logger)

beforeAll(async () => {
const resolver = createTestResolver({ include: ['data/*/loot_tables/**/*.json', 'data/*/tags/**/*.json'] })
await loader.loadFrom(resolver)
}, 10_000)
const { logger, loader } = setupLoader({ include: ['data/*/loot_tables/**/*.json', 'data/*/tags/**/*.json'] })

afterEach(() => {
loader.clear()
Expand Down
4 changes: 2 additions & 2 deletions test/mock/TestResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createResolver, Options } from '@pssbletrngle/pack-resolver'
import { createResolver, IResolver, Options } from '@pssbletrngle/pack-resolver'

export default function createTestResolver(options: Partial<Options> = {}) {
export default function createTestResolver(options: Partial<Options> = {}): IResolver {
return createResolver({ from: 'test/resources', silent: true, ...options })
}
16 changes: 2 additions & 14 deletions test/recipe.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { EMPTY_RECIPE } from '../src/emit/recipe.js'
import PackLoader from '../src/loader/pack.js'
import { ShapedRecipeDefinition } from '../src/parser/recipe/vanilla/shaped.js'
import createTestAcceptor from './mock/TestAcceptor.js'
import createTestLogger from './mock/TestLogger.js'
import createTestResolver from './mock/TestResolver.js'
import setupLoader from './shared/loaderSetup'

Check failure on line 4 in test/recipe.test.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js

const logger = createTestLogger()
const loader = new PackLoader(logger)

beforeAll(async () => {
const resolver = createTestResolver()
await loader.loadFrom(resolver)
}, 10_000)

afterEach(() => {
loader.clear()
})
const { logger, loader } = setupLoader()

it('has no unknown recipe loaders', () => {
expect(logger.warn).not.toHaveBeenCalled()
Expand Down
2 changes: 1 addition & 1 deletion test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// @ts-ignore
import { jest } from '@jest/globals'

beforeAll(() => {
beforeAll(async () => {
global.jest = jest
})
21 changes: 21 additions & 0 deletions test/shared/loaderSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import createTestLogger from '../mock/TestLogger'

Check failure on line 1 in test/shared/loaderSetup.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js
import { PackLoader } from '../../src'

Check failure on line 2 in test/shared/loaderSetup.ts

View workflow job for this annotation

GitHub Actions / test

Directory paths must end with index.js
import createTestResolver from '../mock/TestResolver'

Check failure on line 3 in test/shared/loaderSetup.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js
import { Options } from '@pssbletrngle/pack-resolver'

export default function setupLoader(options?: Partial<Options>) {
const logger = createTestLogger()
const loader = new PackLoader(logger)

beforeAll(async () => {
const resolver = createTestResolver(options)
await loader.loadFrom(resolver)
}, 15_0000)

afterEach(() => {
loader.clear()
logger.reset()
})

return { loader, logger }
}
17 changes: 3 additions & 14 deletions test/tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import PackLoader from '../src/loader/pack.js'
import createTestAcceptor from './mock/TestAcceptor.js'
import createTestLogger from './mock/TestLogger.js'
import createTestResolver from './mock/TestResolver.js'

const logger = createTestLogger()
const loader = new PackLoader(logger)
beforeAll(async () => {
const resolver = createTestResolver({ include: ['data/*/tags/**/*.json'] })
await loader.loadFrom(resolver)
}, 10_000)

afterEach(() => {
loader.clear()
})
import setupLoader from './shared/loaderSetup'

Check failure on line 2 in test/tags.test.ts

View workflow job for this annotation

GitHub Actions / test

Relative imports and exports must end with .js

const { logger, loader } = setupLoader({ include: ['data/*/tags/**/*.json'] })

Check failure on line 4 in test/tags.test.ts

View workflow job for this annotation

GitHub Actions / test

'logger' is assigned a value but never used

describe('loading of tags', () => {
it('loads tags correctly', async () => {
Expand Down

0 comments on commit 20437f3

Please sign in to comment.