From 3701bf2a9919ede40c7834ae97995a259606cbe2 Mon Sep 17 00:00:00 2001 From: Qing Tomlinson Date: Sat, 26 Oct 2024 15:55:02 -0600 Subject: [PATCH] Fix integration tests Integration tests running over a list of components are being skipped. The reason is that the callbacks in `describe()` must be synchronous. See documentation at https://github.com/mochajs/mocha/pull/5046/files and detailed explanation at https://github.com/mochajs/mocha/issues/2975#issuecomment-1004176440. Adapted the affected tests accordingly. --- .../e2e-test-service/attachmentTest.js | 18 ++-- .../e2e-test-service/definitionTest.js | 89 ++++++++++--------- .../e2e-test-service/noticeTest.js | 30 ++++--- 3 files changed, 71 insertions(+), 66 deletions(-) mode change 100755 => 100644 tools/integration/test/integration/e2e-test-service/noticeTest.js diff --git a/tools/integration/test/integration/e2e-test-service/attachmentTest.js b/tools/integration/test/integration/e2e-test-service/attachmentTest.js index 8b7ad5e..56eb383 100644 --- a/tools/integration/test/integration/e2e-test-service/attachmentTest.js +++ b/tools/integration/test/integration/e2e-test-service/attachmentTest.js @@ -5,17 +5,19 @@ const { callFetch } = require('../../../lib/fetch') const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('../testConfig') const { strictEqual } = require('assert') -describe('Validation attachments between dev and prod', async function () { - this.timeout(definition.timeout * 2) +;(async function () { + const components = await getComponents() + describe('Validation attachments between dev and prod', async function () { + this.timeout(definition.timeout * 2) - //Rest a bit to avoid overloading the servers - afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) + //Rest a bit to avoid overloading the servers + afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) - const components = await getComponents() - components.forEach(coordinates => { - it(`should have the same attachement as prod for ${coordinates}`, () => fetchAndCompareAttachments(coordinates)) + components.forEach(coordinates => { + it(`should have the same attachement as prod for ${coordinates}`, () => fetchAndCompareAttachments(coordinates)) + }) }) -}) +})() async function fetchAndCompareAttachments(coordinates) { const expectedAttachments = await findAttachments(prodApiBaseUrl, coordinates) diff --git a/tools/integration/test/integration/e2e-test-service/definitionTest.js b/tools/integration/test/integration/e2e-test-service/definitionTest.js index 164d421..0e88213 100644 --- a/tools/integration/test/integration/e2e-test-service/definitionTest.js +++ b/tools/integration/test/integration/e2e-test-service/definitionTest.js @@ -8,60 +8,61 @@ const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('.. const nock = require('nock') const fs = require('fs') -describe('Validate definitions', function () { - this.timeout(definition.timeout) - - //Rest a bit to avoid overloading the servers - afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) - - describe('Validation between dev and prod', async function () { - before(() => { - loadFixtures().forEach(([url, definition]) => { - nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, definition) +;(async function () { + const components = await getComponents() + describe('Validate definitions', function () { + this.timeout(definition.timeout) + + //Rest a bit to avoid overloading the servers + afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) + + describe('Validation between dev and prod', function () { + before(() => { + loadFixtures().forEach(([url, definition]) => { + nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, definition) + }) + }) + console.info(`Testing definitions for ${JSON.stringify(components)}`) + components.forEach(coordinates => { + it(`should return the same definition as prod for ${coordinates}`, () => fetchAndCompareDefinition(coordinates)) }) }) - const components = await getComponents() - console.info(`Testing definitions for ${JSON.stringify(components)}`) - components.forEach(coordinates => { - it(`should return the same definition as prod for ${coordinates}`, () => fetchAndCompareDefinition(coordinates)) - }) - }) - describe('Validate on dev', async function () { - const components = await getComponents() - const coordinates = components[0] - - describe('Search definitions', function () { - it(`should find definition for ${coordinates}`, async function () { - const [foundDef, expectedDef] = await Promise.all([ - findDefinition(coordinates), - getDefinition(devApiBaseUrl, coordinates) - ]) - deepStrictEqualExpectedEntries(foundDef, omit(expectedDef, ['files'])) + describe('Validate on dev', function () { + const coordinates = components[0] + + describe('Search definitions', function () { + it(`should find definition for ${coordinates}`, async function () { + const [foundDef, expectedDef] = await Promise.all([ + findDefinition(coordinates), + getDefinition(devApiBaseUrl, coordinates) + ]) + deepStrictEqualExpectedEntries(foundDef, omit(expectedDef, ['files'])) + }) }) - }) - describe('Search coordinates via pattern', function () { - it(`should find coordinates for aws-sdk-java`, async function () { - const response = await callFetch(`${devApiBaseUrl}/definitions?pattern=aws-sdk-java`).then(r => r.json()) - ok(response.length > 0) + describe('Search coordinates via pattern', function () { + it(`should find coordinates for aws-sdk-java`, async function () { + const response = await callFetch(`${devApiBaseUrl}/definitions?pattern=aws-sdk-java`).then(r => r.json()) + ok(response.length > 0) + }) }) - }) - describe('Post to /definitions', function () { - it(`should get definition via post to /definitions for ${coordinates}`, async function () { - const postDefinitions = callFetch(`${devApiBaseUrl}/definitions`, buildPostOpts([coordinates])).then(r => - r.json() - ) - const [actualDef, expectedDef] = await Promise.all([ - postDefinitions.then(r => r[coordinates]), - getDefinition(devApiBaseUrl, coordinates) - ]) - deepStrictEqualExpectedEntries(actualDef, expectedDef) + describe('Post to /definitions', function () { + it(`should get definition via post to /definitions for ${coordinates}`, async function () { + const postDefinitions = callFetch(`${devApiBaseUrl}/definitions`, buildPostOpts([coordinates])).then(r => + r.json() + ) + const [actualDef, expectedDef] = await Promise.all([ + postDefinitions.then(r => r[coordinates]), + getDefinition(devApiBaseUrl, coordinates) + ]) + deepStrictEqualExpectedEntries(actualDef, expectedDef) + }) }) }) }) -}) +})() async function fetchAndCompareDefinition(coordinates) { const [recomputedDef, expectedDef] = await Promise.all([ diff --git a/tools/integration/test/integration/e2e-test-service/noticeTest.js b/tools/integration/test/integration/e2e-test-service/noticeTest.js old mode 100755 new mode 100644 index d366b1a..ba02a82 --- a/tools/integration/test/integration/e2e-test-service/noticeTest.js +++ b/tools/integration/test/integration/e2e-test-service/noticeTest.js @@ -7,24 +7,26 @@ const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('.. const nock = require('nock') const fs = require('fs') -describe('Validate notice files between dev and prod', async function () { - this.timeout(definition.timeout) +;(async function () { + const components = await getComponents() + describe('Validate notice files between dev and prod', async function () { + this.timeout(definition.timeout) - //Rest a bit to avoid overloading the servers - afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) + //Rest a bit to avoid overloading the servers + afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) - before(() => { - loadFixtures().forEach(([coordinatesString, notice]) => { - nock(prodApiBaseUrl, { allowUnmocked: true }) - .post('/notices', { coordinates: [coordinatesString] }) - .reply(200, notice) + before(() => { + loadFixtures().forEach(([coordinatesString, notice]) => { + nock(prodApiBaseUrl, { allowUnmocked: true }) + .post('/notices', { coordinates: [coordinatesString] }) + .reply(200, notice) + }) + }) + components.forEach(coordinates => { + it(`should return the same notice as prod for ${coordinates}`, () => fetchAndCompareNotices(coordinates)) }) }) - const components = await getComponents() - components.forEach(coordinates => { - it(`should return the same notice as prod for ${coordinates}`, () => fetchAndCompareNotices(coordinates)) - }) -}) +})() async function fetchAndCompareNotices(coordinates) { const [computedNotice, expectedNotice] = await Promise.all(