diff --git a/src/convert/replacements.ts b/src/convert/replacements.ts index 2ad1fd3eda..62a6cb1dbc 100644 --- a/src/convert/replacements.ts +++ b/src/convert/replacements.ts @@ -230,4 +230,4 @@ export const stringToRegex = (input: string): RegExp => // eslint-disable-next-line no-useless-escape new RegExp(input.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'); -const posixifyPaths = (f: string): string => f.split(sep).join(posix.sep); +export const posixifyPaths = (f: string): string => f.split(sep).join(posix.sep); diff --git a/test/convert/replacements.test.ts b/test/convert/replacements.test.ts index 9e02136352..399c3f99e5 100644 --- a/test/convert/replacements.test.ts +++ b/test/convert/replacements.test.ts @@ -8,7 +8,13 @@ import * as path from 'path'; import { assert, expect } from 'chai'; import Sinon = require('sinon'); import { Lifecycle } from '@salesforce/core'; -import { getReplacements, matchesFile, replacementIterations, stringToRegex } from '../../src/convert/replacements'; +import { + getReplacements, + matchesFile, + replacementIterations, + stringToRegex, + posixifyPaths, +} from '../../src/convert/replacements'; import { matchingContentFile } from '../mock'; import * as replacementsForMock from '../../src/convert/replacements'; @@ -63,7 +69,8 @@ describe('marking replacements on a component', () => { it('marks a string replacement from env', async () => { assert(cmp.xml); const result = await getReplacements(cmp, [ - { filename: cmp.xml, stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, + // spec says filename path should be posix. The mocks are using join, so on windows they are wrong + { filename: posixifyPaths(cmp.xml), stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, ]); expect(result).to.deep.equal({ [cmp.xml]: [ @@ -78,7 +85,9 @@ describe('marking replacements on a component', () => { }); it('marks string replacements from file', async () => { assert(cmp.xml); - const result = await getReplacements(cmp, [{ filename: cmp.xml, stringToReplace: 'foo', replaceWithFile: 'bar' }]); + const result = await getReplacements(cmp, [ + { filename: posixifyPaths(cmp.xml), stringToReplace: 'foo', replaceWithFile: 'bar' }, + ]); expect(result).to.deep.equal({ [cmp.xml]: [ { @@ -94,7 +103,7 @@ describe('marking replacements on a component', () => { it('marks regex replacements on a matching file', async () => { assert(cmp.xml); const result = await getReplacements(cmp, [ - { filename: cmp.xml, regexToReplace: '.*foo.*', replaceWithEnv: 'FOO_REPLACEMENT' }, + { filename: posixifyPaths(cmp.xml), regexToReplace: '.*foo.*', replaceWithEnv: 'FOO_REPLACEMENT' }, ]); expect(result).to.deep.equal({ [cmp.xml]: [ @@ -110,8 +119,8 @@ describe('marking replacements on a component', () => { it('marks 2 replacements on one file', async () => { assert(cmp.xml); const result = await getReplacements(cmp, [ - { filename: cmp.xml, stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, - { filename: cmp.xml, stringToReplace: 'baz', replaceWithEnv: 'FOO_REPLACEMENT' }, + { filename: posixifyPaths(cmp.xml), stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, + { filename: posixifyPaths(cmp.xml), stringToReplace: 'baz', replaceWithEnv: 'FOO_REPLACEMENT' }, ]); expect(result).to.deep.equal({ [cmp.xml]: [ @@ -159,8 +168,8 @@ describe('marking replacements on a component', () => { assert(cmp.content); assert(cmp.xml); const result = await getReplacements(cmp, [ - { filename: cmp.xml, stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, - { filename: cmp.content, stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, + { filename: posixifyPaths(cmp.xml), stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, + { filename: posixifyPaths(cmp.content), stringToReplace: 'foo', replaceWithEnv: 'FOO_REPLACEMENT' }, ]); expect(result).to.deep.equal({ [cmp.xml]: [