From 897261efdc243481a8510b0addb75ab0fb619b9e Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 27 Aug 2018 12:13:02 +0300 Subject: [PATCH] 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 --- .../dockerbuild/scripts-js/test/common/utils.spec.ts | 3 ++- .../test/preview-server/build-retriever.spec.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/utils.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/utils.spec.ts index 68472c4740..063268cce5 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/utils.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/utils.spec.ts @@ -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')); }); }); diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/preview-server/build-retriever.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/preview-server/build-retriever.spec.ts index 45939ed069..6f8746712b 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/preview-server/build-retriever.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/preview-server/build-retriever.spec.ts @@ -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(); });