Skip to content

Commit

Permalink
try waiting until requests to the tunnel work
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Oct 2, 2024
1 parent da449e5 commit ba28482
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jest.config.appscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
rootDir: 'tests/appscript',
preset: 'ts-jest/presets/js-with-ts-esm',
testEnvironment: 'node',
testTimeout: 180000,
testTimeout: 300000,
globalSetup: '../globalSetup.js',
globalTeardown: '../globalTeardown.js',
maxWorkers: 1, // since we run our tests within apps script, we can't run them in parallel
Expand Down
27 changes: 24 additions & 3 deletions tests/appscript/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { beforeEach, beforeAll, expect } from '@jest/globals';
import Clasp from '../utilities/clasp';
import { makeApiFailureMockServer } from './api/mockServer';
import axios from 'axios';

describe('api', () => {
let server: ReturnType<typeof makeApiFailureMockServer>;
Expand Down Expand Up @@ -47,6 +48,26 @@ describe('api', () => {
});
}

async function waitForMockServer() {
const testUrl = `${tunnel.url}/index.php`;
const body = {
method: 'SitesManager.getSitesIdWithAtLeastViewAccess',
};

while (true) {
await new Promise((resolve) => setTimeout(resolve, 2000));

try {
const response = await axios.post(testUrl, body);
if (Array.isArray(response.data) && response.data[0] === 1) {
return;
}
} catch (e) {
// retry
}
}
}

describe('extractBasicAuthFromUrl()', () => {
const URLS_WITHOUT_CREDENTIALS = [
'http://mymatomo.com/',
Expand Down Expand Up @@ -129,7 +150,7 @@ describe('api', () => {
},
});

await new Promise((resolve) => setTimeout(resolve, 10000));
await waitForMockServer();

// use the mock server's path that forces a random error
const result = await Clasp.run('setCredentials', {
Expand Down Expand Up @@ -175,7 +196,7 @@ describe('api', () => {
});

// waiting seems to be required here, or the mock server isn't used in time
await new Promise((resolve) => setTimeout(resolve, 10000));
await waitForMockServer();

// use the mock server's path that forces a non-random error
await Clasp.run('setCredentials', {
Expand Down Expand Up @@ -218,7 +239,7 @@ describe('api', () => {
},
});

await new Promise((resolve) => setTimeout(resolve, 10000));
await waitForMockServer();

// use the mock server's path that forces a non-random error
await Clasp.run('setCredentials', {
Expand Down

0 comments on commit ba28482

Please sign in to comment.