test(docs-infra): fix preview server unit tests on Windows (#25671)

Some tests where comparing actual with expected paths, without taking
into account that paths will be different on Windows.

This commit uses `path.resolve()` to convert expected paths to their
OS-specific form.

PR Close #25671
This commit is contained in:
George Kalpakas 2018-08-27 12:13:02 +03:00 committed by Kara Erickson
parent 35d70ff265
commit 897261efdc
2 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,5 @@
// Imports
import {resolve as resolvePath} from 'path';
import {
assert,
assertNotMissingOrEmpty,
@ -39,7 +40,7 @@ describe('utils', () => {
const sha = 'ABCDEF1234567';
const artifactPath = 'a/path/to/file.zip';
const path = computeArtifactDownloadPath(downloadDir, pr, sha, artifactPath);
expect(path).toEqual('/a/b/c/123-ABCDEF1-file.zip');
expect(path).toBe(resolvePath('/a/b/c/123-ABCDEF1-file.zip'));
});
});

View File

@ -1,12 +1,13 @@
import * as fs from 'fs';
import * as nock from 'nock';
import {resolve as resolvePath} from 'path';
import {BuildInfo, CircleCiApi} from '../../lib/common/circle-ci-api';
import {Logger} from '../../lib/common/utils';
import {BuildRetriever} from '../../lib/preview-server/build-retriever';
describe('BuildRetriever', () => {
const MAX_DOWNLOAD_SIZE = 10000;
const DOWNLOAD_DIR = '/DOWNLOAD/DIR';
const DOWNLOAD_DIR = resolvePath('/DOWNLOAD/DIR');
const BASE_URL = 'http://test.com';
const ARTIFACT_PATH = '/some/path/build.zip';
@ -131,11 +132,14 @@ describe('BuildRetriever', () => {
it('should write the artifact file to disk', async () => {
const artifactRequest = nock(BASE_URL).get(ARTIFACT_PATH).reply(200, ARTIFACT_CONTENTS);
const downloadPath = resolvePath(`${DOWNLOAD_DIR}/777-COMMIT-build.zip`);
await retriever.downloadBuildArtifact(12345, 777, 'COMMIT', ARTIFACT_PATH);
expect(writeFileSpy)
.toHaveBeenCalledWith(`${DOWNLOAD_DIR}/777-COMMIT-build.zip`, jasmine.any(Buffer), jasmine.any(Function));
expect(writeFileSpy).toHaveBeenCalledWith(downloadPath, jasmine.any(Buffer), jasmine.any(Function));
const buffer: Buffer = writeFileSpy.calls.mostRecent().args[1];
expect(buffer.toString()).toEqual(ARTIFACT_CONTENTS);
artifactRequest.done();
});