-
Locally I'm seeing no issues, but on CI I'm seeing this:
My setup file for vitest: import { afterAll, afterEach, beforeAll, vi } from 'vitest';
import { server } from './msw/node.js';
beforeAll(() => {
server.listen({
onUnhandledRequest: 'error',
});
});
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
}); The import { setupServer } from 'msw/node';
import { handlers } from './handlers.js';
export const server = setupServer(...handlers); Test of import { describe, expect, it } from 'vitest';
import { HttpResponse } from 'msw';
import { logger } from '../logger.js';
import type { ProfitLossInput } from '../../../graphql/index.js';
import { getProfitLoss } from './get-profit-and-loss-report.js';
import type { CodatProfitAndLossReport } from './mappings/profit-and-loss-report.js';
import {
codatApiUrl,
createProfitAndLossReport,
} from '#/test/fixtures/codat.js';
import { type ResBody, http } from '#/test/msw/http.js';
import { server } from '#/test/msw/node.js';
const profitAndLostUrl = `${codatApiUrl}/companies/:companyId/data/financials/profitAndLoss`;
describe('get-profit-and-loss-report', () => {
describe('getProfitLoss', () => {
it('triggers expected actions', async () => {
server.boundary(async () => {
const report = createProfitAndLossReport();
server.use(
http.get<ResBody<CodatProfitAndLossReport>>(profitAndLostUrl, () => {
return HttpResponse.json(report);
}),
);
const curYear = new Date().getFullYear();
const input: ProfitLossInput = {
companyId: '123',
fromDate: new Date(curYear - 10, 0).toISOString(),
toDate: new Date(curYear + 10, 11).toISOString(),
};
const result = await getProfitLoss({ input, logger });
expect(result.reports).toHaveLength(report.reports.length);
});
});
});
}); Update: it('triggers expected actions', server.boundary(async () => {
const report = createProfitAndLossReport();
server.use(
http.get<ResBody<CodatProfitAndLossReport>>(profitAndLostUrl, () => {
return HttpResponse.json(report);
}),
);
const curYear = new Date().getFullYear();
const input: ProfitLossInput = {
companyId: '123',
fromDate: new Date(curYear - 10, 0).toISOString(),
toDate: new Date(curYear + 10, 11).toISOString(),
};
const result = await getProfitLoss({ input, logger });
expect(result.reports).toHaveLength(report.reports.length);
})); This then runs into a bit of a compatibility issue with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Ok so I still have issues on CI and part of the potential solution here is a little bit tedious if you use vitest context throught extend If you aren't using extend or vitest context: it('test name', server.boundary(async () => {
server.use(
http.get('someUrl, () => {
return HttpResponse.json(someData);
}),
);
const result = await someFn({ input, logger });
expect(result.data).toHaveLength(fixture.data.length);
})); If you are using vitest's context: it('test name', async ({ extraContextStuff, expect }) => {
const fn = server.boundary(async () => {
server.use(
http.ge(url, () => {
return HttpResponse.json(data);
}),
);
const result = await someFn()
expect(result).toMatchObject(objToMatch);
});
await fn();
}); or it('test name', async ({ extraContextStuff, expect }) => {
await server.boundary(async () => {
server.use(
http.ge(url, () => {
return HttpResponse.json(data);
}),
);
const result = await someFn()
expect(result).toMatchObject(objToMatch);
})()
}); |
Beta Was this translation helpful? Give feedback.
-
Alright, so I tracked down this issue. I'll need to make a simple test case so this could potentially be examined closer. |
Beta Was this translation helpful? Give feedback.
Alright, so I tracked down this issue.
@aws-sdk/client-ssm
has some form of compatibility issue w/msw. It'll work almost all the time fine locally (I did notice thathttps
always failed locally), but as soon as this is up on CI it failed no matter what.I'll need to make a simple test case so this could potentially be examined closer.