diff --git a/test/ingredient.test.ts b/test/ingredient.test.ts index 882b8c3..526af6d 100644 --- a/test/ingredient.test.ts +++ b/test/ingredient.test.ts @@ -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' -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 () => { diff --git a/test/loot.test.ts b/test/loot.test.ts index 60bfe27..e0ce73a 100644 --- a/test/loot.test.ts +++ b/test/loot.test.ts @@ -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' -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() diff --git a/test/mock/TestResolver.ts b/test/mock/TestResolver.ts index 0127190..4db1ceb 100644 --- a/test/mock/TestResolver.ts +++ b/test/mock/TestResolver.ts @@ -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 = {}) { +export default function createTestResolver(options: Partial = {}): IResolver { return createResolver({ from: 'test/resources', silent: true, ...options }) } diff --git a/test/recipe.test.ts b/test/recipe.test.ts index ce9f36e..07c2da7 100644 --- a/test/recipe.test.ts +++ b/test/recipe.test.ts @@ -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' -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() diff --git a/test/setup.ts b/test/setup.ts index b03a76b..f94c1a5 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -2,6 +2,6 @@ // @ts-ignore import { jest } from '@jest/globals' -beforeAll(() => { +beforeAll(async () => { global.jest = jest }) diff --git a/test/shared/loaderSetup.ts b/test/shared/loaderSetup.ts new file mode 100644 index 0000000..530aee1 --- /dev/null +++ b/test/shared/loaderSetup.ts @@ -0,0 +1,21 @@ +import createTestLogger from '../mock/TestLogger' +import { PackLoader } from '../../src' +import createTestResolver from '../mock/TestResolver' +import { Options } from '@pssbletrngle/pack-resolver' + +export default function setupLoader(options?: Partial) { + 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 } +} diff --git a/test/tags.test.ts b/test/tags.test.ts index e5bd00e..988f29c 100644 --- a/test/tags.test.ts +++ b/test/tags.test.ts @@ -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' + +const { logger, loader } = setupLoader({ include: ['data/*/tags/**/*.json'] }) describe('loading of tags', () => { it('loads tags correctly', async () => {