Merge pull request #2226 from spotify/rugvip/wintest

Make tests work on Windows and run as part of Windows master build
This commit is contained in:
Patrik Oldsberg
2020-09-07 13:50:18 +02:00
committed by GitHub
14 changed files with 153 additions and 116 deletions
@@ -47,21 +47,21 @@ describe('createRouter', () => {
const response = await request(app).get('/index.html');
expect(response.status).toBe(200);
expect(response.text).toBe('this is index.html\n');
expect(response.text.trim()).toBe('this is index.html');
});
it('returns other.html', async () => {
const response = await request(app).get('/other.html');
expect(response.status).toBe(200);
expect(response.text).toBe('this is other.html\n');
expect(response.text.trim()).toBe('this is other.html');
});
it('returns index.html if missing', async () => {
const response = await request(app).get('/missing.html');
expect(response.status).toBe(200);
expect(response.text).toBe('this is index.html\n');
expect(response.text.trim()).toBe('this is index.html');
});
});
@@ -83,11 +83,11 @@ describe('createRouter with static fallback handler', () => {
const response1 = await request(app).get('/static/main.txt');
expect(response1.status).toBe(200);
expect(response1.text).toBe('this is main.txt\n');
expect(response1.text.trim()).toBe('this is main.txt');
const response2 = await request(app).get('/static/test.txt');
expect(response2.status).toBe(200);
expect(response2.text).toBe('this is test.txt');
expect(response2.text.trim()).toBe('this is test.txt');
const response3 = await request(app).get('/static/missing.txt');
expect(response3.status).toBe(404);
@@ -96,6 +96,8 @@ describe('GitHubPreparer', () => {
mockEntity.spec.path = './template/test/1/2/3';
const response = await preparer.prepare(mockEntity);
expect(response).toMatch(new RegExp(/\/template\/test\/1\/2\/3$/));
expect(response.split('\\').join('/')).toMatch(
/\/template\/test\/1\/2\/3$/,
);
});
});
@@ -20,6 +20,13 @@ import Docker from 'dockerode';
import { runDockerContainer } from './helpers';
describe('helpers', () => {
if (process.platform === 'win32') {
// eslint-disable-next-line jest/no-focused-tests
it.only('should skip tests on windows', () => {
expect('test').not.toBe('run');
});
}
const mockDocker = new Docker() as jest.Mocked<Docker>;
beforeEach(() => {
@@ -17,6 +17,13 @@ import { DirectoryPreparer } from './dir';
import { getVoidLogger } from '@backstage/backend-common';
import { checkoutGitRepository } from './helpers';
function normalizePath(path: string) {
return path
.replace(/^[a-z]:/i, '')
.split('\\')
.join('/');
}
jest.mock('./helpers', () => ({
...jest.requireActual<{}>('./helpers'),
checkoutGitRepository: jest.fn(() => '/tmp/backstage-repo/org/name/branch/'),
@@ -47,7 +54,7 @@ describe('directory preparer', () => {
'backstage.io/techdocs-ref': 'dir:./our-documentation',
});
expect(await directoryPreparer.prepare(mockEntity)).toEqual(
expect(normalizePath(await directoryPreparer.prepare(mockEntity))).toEqual(
'/directory/our-documentation',
);
});
@@ -61,7 +68,7 @@ describe('directory preparer', () => {
'backstage.io/techdocs-ref': 'dir:/our-documentation/techdocs',
});
expect(await directoryPreparer.prepare(mockEntity)).toEqual(
expect(normalizePath(await directoryPreparer.prepare(mockEntity))).toEqual(
'/our-documentation/techdocs',
);
});
@@ -75,7 +82,7 @@ describe('directory preparer', () => {
'backstage.io/techdocs-ref': 'dir:./docs',
});
expect(await directoryPreparer.prepare(mockEntity)).toEqual(
expect(normalizePath(await directoryPreparer.prepare(mockEntity))).toEqual(
'/tmp/backstage-repo/org/name/branch/docs',
);
expect(checkoutGitRepository).toHaveBeenCalledTimes(1);
@@ -18,6 +18,13 @@ import { getVoidLogger } from '@backstage/backend-common';
import { GithubPreparer } from './github';
import { checkoutGithubRepository } from './helpers';
function normalizePath(path: string) {
return path
.replace(/^[a-z]:/i, '')
.split('\\')
.join('/');
}
jest.mock('./helpers', () => ({
...jest.requireActual<{}>('./helpers'),
checkoutGithubRepository: jest.fn(
@@ -51,7 +58,7 @@ describe('github preparer', () => {
const tempDocsPath = await preparer.prepare(mockEntity);
expect(checkoutGithubRepository).toHaveBeenCalledTimes(1);
expect(tempDocsPath).toEqual(
expect(normalizePath(tempDocsPath)).toEqual(
'/tmp/backstage-repo/org/name/branch/plugins/techdocs-backend/examples/documented-component',
);
});