From 7d200a61e4eb967f1c3ca50d5c8942868dd12c3b Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Tue, 10 Sep 2024 19:33:40 -0300 Subject: [PATCH] test: support async extension --- test/antoraConfig.json | 5 ++++- test/extension.test.mjs | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/test/antoraConfig.json b/test/antoraConfig.json index 6242933..4c39dca 100644 --- a/test/antoraConfig.json +++ b/test/antoraConfig.json @@ -13,7 +13,10 @@ } }, "playbook": { - "dir": "@dirname" + "dir": "@dirname", + "runtime": { + "cacheDir": null + } }, "contentAggregate": [ { diff --git a/test/extension.test.mjs b/test/extension.test.mjs index 043b868..76c9839 100644 --- a/test/extension.test.mjs +++ b/test/extension.test.mjs @@ -94,11 +94,12 @@ function parseInput(input) { } -describe('The extension produces links to C++ symbols', () => { +test('The extension produces links to C++ symbols', async (t) => { // ============================================================ // Create extension object // ============================================================ - const antoraConfigFileContent = fs.readFileSync("test/antoraConfig.json", 'utf8') + const antoraConfigPath = path.resolve(__dirname, 'antoraConfig.json') + const antoraConfigFileContent = fs.readFileSync(antoraConfigPath, 'utf8') const {config, playbook, contentAggregate} = JSON.parse(antoraConfigFileContent) playbook.dir = __dirname for (let content of contentAggregate) { @@ -108,19 +109,32 @@ describe('The extension produces links to C++ symbols', () => { } const antoraContext = new generatorContext() const extension = new CppTagfilesExtension(antoraContext, {config, playbook}) - extension.onContentAggregated({playbook, contentAggregate}) + await extension.onContentAggregated({playbook, contentAggregate}) // ============================================================ // Load fixtures.json file with node.js built-in filesystem module // ============================================================ - const fileContent = fs.readFileSync("test/fixtures.json", 'utf8') + const fixturesPath = path.resolve(__dirname, 'fixtures.json') + const fileContent = fs.readFileSync(fixturesPath, 'utf8') const fixtures = JSON.parse(fileContent) + await t.test('The extension object is created', () => { + ok(extension) + }) + + await t.test('The extension object has a process method', () => { + ok(extension.process) + }) + + await t.test('The fixtures file is loaded', () => { + ok(fixtures) + }) + // ============================================================ // Iterate fixtures and run tests // ============================================================ for (const {name, tests} of fixtures) { - test(name, () => { + await t.test(name, async () => { for (const {input, output, component, attributes} of tests) { // Create a parent object with the component // parent?.document?.getAttributes()['page-component-name'] should return the component name @@ -143,4 +157,5 @@ describe('The extension produces links to C++ symbols', () => { } }) } + }); \ No newline at end of file