From 3f896c8e1832cafaf404ba91adbabcdfed290216 Mon Sep 17 00:00:00 2001 From: Tom Auger <31711089+tom-auger@users.noreply.github.com> Date: Fri, 10 Aug 2018 16:21:52 +0100 Subject: [PATCH] Fix Jest tests that fail on Windows (#896) * Fix failing tests * Suppress build output in build tests --- lib/__tests__/build-files.test.js | 2 +- lib/server/__tests__/docs.test.js | 3 ++- lib/server/utils.js | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/__tests__/build-files.test.js b/lib/__tests__/build-files.test.js index 1297567879..e2b5b7ed0c 100644 --- a/lib/__tests__/build-files.test.js +++ b/lib/__tests__/build-files.test.js @@ -28,7 +28,7 @@ let outputAssetsFiles = []; function generateSite() { shell.cd('website'); - shell.exec('yarn build'); + shell.exec('yarn build', {silent: true}); } function clearBuildFolder() { diff --git a/lib/server/__tests__/docs.test.js b/lib/server/__tests__/docs.test.js index 19ec0e7c1a..6410b235f2 100644 --- a/lib/server/__tests__/docs.test.js +++ b/lib/server/__tests__/docs.test.js @@ -89,7 +89,8 @@ describe('getFile', () => { fs.existsSync = jest.fn().mockReturnValue(true); fs.readFileSync = jest.fn().mockImplementation(file => { const fakePath = file.replace(process.cwd().replace(/website$/, ''), ''); - return fakeContent[fakePath]; + const normalizedPath = fakePath.replace(/\\/g, '/'); + return fakeContent[normalizedPath]; }); test('docs does not exist', () => { diff --git a/lib/server/utils.js b/lib/server/utils.js index d93c71265b..1f353db9e1 100644 --- a/lib/server/utils.js +++ b/lib/server/utils.js @@ -17,8 +17,10 @@ function getSubDir(file, refDir) { } function getLanguage(file, refDir) { + const separator = escapeStringRegexp(path.sep); + const baseDir = escapeStringRegexp(path.basename(refDir)); const regexSubFolder = new RegExp( - `${escapeStringRegexp(path.basename(refDir))}/(.*?)/.*` + `${baseDir}${separator}(.*?)${separator}.*` ); const match = regexSubFolder.exec(file);