From facd78820c7178a25c0d49d40e12ff5d71af51a9 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Thu, 26 Oct 2017 20:51:47 -0400 Subject: [PATCH 1/2] Enables running tests on Windows via Appveyor --- .appveyor.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..6103565 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,21 @@ +# Test against the latest version of this Node.js version +environment: + nodejs_version: "8" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm test + +# Don't actually build. +build: off \ No newline at end of file From 882a14821cc5f3282d4f4cc763e387deddef94f3 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Thu, 26 Oct 2017 20:47:36 -0400 Subject: [PATCH 2/2] Add support for Windows - path manipulation and comparison operations were assuming posix-style paths. Adds a bit of normalization so that paths on Windows are always converted to use forward-slashes. This is fine because Windows treats both as path delimeters and forward slashes are not valid in directory or file names. --- src/DeclarationIndex.ts | 4 ++-- src/utilities/PathHelpers.ts | 13 ++++++++++++- test/declaration-index/DeclarationIndex.spec.ts | 2 +- .../DeclarationIndex.body-parser.spec.ts | 2 +- ...nIndex.reindex-with-global-module-export.spec.ts | 2 +- test/testUtilities.ts | 13 ++++++++++++- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/DeclarationIndex.ts b/src/DeclarationIndex.ts index f16ccc8..6514b36 100644 --- a/src/DeclarationIndex.ts +++ b/src/DeclarationIndex.ts @@ -12,7 +12,7 @@ import { Namespace } from './resources/Namespace'; import { Resource } from './resources/Resource'; import { isExportableDeclaration } from './type-guards/TypescriptHeroGuards'; import { TypescriptParser } from './TypescriptParser'; -import { normalizeFilename, normalizePathUri } from './utilities/PathHelpers'; +import { normalizeFilename, normalizePathUri, toPosix } from './utilities/PathHelpers'; /** * Returns the name of the node folder. Is used as the library name for indexing. @@ -308,7 +308,7 @@ export class DeclarationIndex { break; } if (ex instanceof AllExport || ex instanceof NamedExport) { - const exported = '/' + relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from))); + const exported = '/' + toPosix(relative(this.rootPath, normalize(join(resource.parsedPath.dir, ex.from)))); exportsResource = exported === resourcePath; } } diff --git a/src/utilities/PathHelpers.ts b/src/utilities/PathHelpers.ts index a9b3096..753ed24 100644 --- a/src/utilities/PathHelpers.ts +++ b/src/utilities/PathHelpers.ts @@ -25,5 +25,16 @@ export function normalizePathUri(uri: string): string { * @returns {string} */ export function normalizeFilename(filepath: string): string { - return filepath.replace(/([.]d)?[.](t|j)sx?$/g, ''); + return toPosix(filepath.replace(/([.]d)?[.](t|j)sx?$/g, '')); +} + +/** + * On Windows, replaces all backslash delimeters with forward slashes. + * On other OSes, returns the path unmodified. + */ +export function toPosix(path: string): string { + if (platform() === 'win32') { + return path.replace(/\\/g, '/'); + } + return path; } diff --git a/test/declaration-index/DeclarationIndex.spec.ts b/test/declaration-index/DeclarationIndex.spec.ts index eafa7dc..17620cf 100644 --- a/test/declaration-index/DeclarationIndex.spec.ts +++ b/test/declaration-index/DeclarationIndex.spec.ts @@ -1,5 +1,5 @@ import mockFs = require('mock-fs'); -import { join, resolve } from 'path'; +import { join, resolve } from '../testUtilities'; import { DeclarationIndex } from '../../src/DeclarationIndex'; import { ClassDeclaration } from '../../src/declarations'; diff --git a/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts b/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts index 8d3acb3..cb1ae08 100644 --- a/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts +++ b/test/declaration-index/specific-cases/body-parser/DeclarationIndex.body-parser.spec.ts @@ -1,4 +1,4 @@ -import { join, resolve } from 'path'; +import { join, resolve } from '../../../testUtilities'; import { DeclarationIndex } from '../../../../src/DeclarationIndex'; import { TypescriptParser } from '../../../../src/TypescriptParser'; diff --git a/test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts b/test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts index 781497c..39959e7 100644 --- a/test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts +++ b/test/declaration-index/specific-cases/reindex-with-global-module/DeclarationIndex.reindex-with-global-module-export.spec.ts @@ -1,5 +1,5 @@ import { FileChanges } from '../../../../src'; -import { join, resolve } from 'path'; +import { join, resolve } from '../../../testUtilities'; import { DeclarationIndex } from '../../../../src/DeclarationIndex'; import { TypescriptParser } from '../../../../src/TypescriptParser'; diff --git a/test/testUtilities.ts b/test/testUtilities.ts index 6257622..fd2a6f7 100644 --- a/test/testUtilities.ts +++ b/test/testUtilities.ts @@ -1,7 +1,18 @@ -import { resolve } from 'path'; +import * as Path from 'path'; +import { toPosix } from '../src/utilities/PathHelpers'; export function getWorkspaceFile(pathFromWorkspace: string): string { return resolve(__dirname, '_workspace', pathFromWorkspace); } +// Like path.resolve, but always replaces backslashes with forward slashes on Windows. +export function resolve(...paths: string[]): string { + return toPosix(Path.resolve(...paths)); +} + +// Like path.join, but always replaces backslashes with forward slashes on Windows. +export function join(...paths: string[]): string { + return toPosix(Path.join(...paths)); +} + export const rootPath = resolve(__dirname, '_workspace');