From a8d529ba8476434723ad15ede96106719fd00fdc Mon Sep 17 00:00:00 2001 From: Ka-wai Wong Date: Wed, 6 Mar 2019 15:56:25 -0800 Subject: [PATCH 1/2] Fix extractSourceFiles tests to work cross platform --- server/src/utilities/extractSourceFiles.test.ts | 8 +++++--- server/src/utilities/extractSourceFiles.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/utilities/extractSourceFiles.test.ts b/server/src/utilities/extractSourceFiles.test.ts index a581ad9..cf45204 100644 --- a/server/src/utilities/extractSourceFiles.test.ts +++ b/server/src/utilities/extractSourceFiles.test.ts @@ -1,4 +1,6 @@ const globby = require('globby'); +import { join } from 'path'; + import extractSourceFiles from './extractSourceFiles'; describe('extractSourceFiles.ts', () => { @@ -12,16 +14,16 @@ describe('extractSourceFiles.ts', () => { it('should not error out', () => { extractSourceFiles('test'); - expect(globby.sync).toHaveBeenLastCalledWith([ `test\\**\\*.+(js|jsx|ts|tsx)`, '!**\\node_modules' ]); + expect(globby.sync).toHaveBeenLastCalledWith([ join('test', '**', '*.+(js|jsx|ts|tsx)'), join('!**', 'node_modules') ]); }); it('should handle a Windows style path', () => { extractSourceFiles('file:///c:/some/windows/style/path'); - expect(globby.sync).toHaveBeenLastCalledWith([ `\\some\\windows\\style\\path\\**\\*.+(js|jsx|ts|tsx)`, '!**\\node_modules' ]); + expect(globby.sync).toHaveBeenLastCalledWith([ join('/', 'some', 'windows', 'style', 'path', '**', '*.+(js|jsx|ts|tsx)'), join('!**', 'node_modules') ]); }); it('should handle a Windows style path with an escaped colon', () => { extractSourceFiles('file:///c%3A/some/windows/style/path'); - expect(globby.sync).toHaveBeenLastCalledWith([ `\\some\\windows\\style\\path\\**\\*.+(js|jsx|ts|tsx)`, '!**\\node_modules' ]); + expect(globby.sync).toHaveBeenLastCalledWith([ join('/', 'some', 'windows', 'style', 'path', '**', '*.+(js|jsx|ts|tsx)'), join('!**', 'node_modules') ]); }); }); diff --git a/server/src/utilities/extractSourceFiles.ts b/server/src/utilities/extractSourceFiles.ts index 72643ee..4bdc8f4 100644 --- a/server/src/utilities/extractSourceFiles.ts +++ b/server/src/utilities/extractSourceFiles.ts @@ -15,7 +15,7 @@ function extractSourceFiles (rootDirectory: string): string[] { normalized = normalized.substring(escapedColonIndex + 3); } - const files = sync([ join(normalize(normalized), '**', '*.+(js|jsx|ts|tsx)'), join('!**', 'node_modules') ]); + const files = sync([ join(normalized, '**', '*.+(js|jsx|ts|tsx)'), join('!**', 'node_modules') ]); return files; } From 8e09c728d1118654cf0fdd3774f780b2f813f155 Mon Sep 17 00:00:00 2001 From: Ka-wai Wong Date: Wed, 6 Mar 2019 15:57:33 -0800 Subject: [PATCH 2/2] Remove unused import in extractSourceFiles.ts --- server/src/utilities/extractSourceFiles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/utilities/extractSourceFiles.ts b/server/src/utilities/extractSourceFiles.ts index 4bdc8f4..6469483 100644 --- a/server/src/utilities/extractSourceFiles.ts +++ b/server/src/utilities/extractSourceFiles.ts @@ -1,5 +1,5 @@ import { sync } from 'globby'; -import { join, normalize } from 'path'; +import { join } from 'path'; function extractSourceFiles (rootDirectory: string): string[] { let normalized = rootDirectory;