Skip to content

Commit

Permalink
test: posixify paths in test configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 5, 2023
1 parent 832e03b commit 7508f93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/convert/replacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
25 changes: 17 additions & 8 deletions test/convert/replacements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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]: [
Expand All @@ -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]: [
{
Expand All @@ -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]: [
Expand All @@ -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]: [
Expand Down Expand Up @@ -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]: [
Expand Down

2 comments on commit 7508f93

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 7508f93 Previous: c970821 Ratio
eda-componentSetCreate-linux 231 ms 340 ms 0.68
eda-sourceToMdapi-linux 5672 ms 7157 ms 0.79
eda-sourceToZip-linux 4806 ms 5342 ms 0.90
eda-mdapiToSource-linux 4337 ms 4523 ms 0.96
lotsOfClasses-componentSetCreate-linux 477 ms 442 ms 1.08
lotsOfClasses-sourceToMdapi-linux 9314 ms 9973 ms 0.93
lotsOfClasses-sourceToZip-linux 7200 ms 7761 ms 0.93
lotsOfClasses-mdapiToSource-linux 5022 ms 4998 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 805 ms 753 ms 1.07
lotsOfClassesOneDir-sourceToMdapi-linux 13080 ms 13223 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 11297 ms 11782 ms 0.96
lotsOfClassesOneDir-mdapiToSource-linux 9027 ms 9316 ms 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 7508f93 Previous: c970821 Ratio
eda-componentSetCreate-win32 497 ms 394 ms 1.26
eda-sourceToMdapi-win32 8892 ms 7782 ms 1.14
eda-sourceToZip-win32 6145 ms 6038 ms 1.02
eda-mdapiToSource-win32 10189 ms 7930 ms 1.28
lotsOfClasses-componentSetCreate-win32 1076 ms 826 ms 1.30
lotsOfClasses-sourceToMdapi-win32 13527 ms 11877 ms 1.14
lotsOfClasses-sourceToZip-win32 9494 ms 7887 ms 1.20
lotsOfClasses-mdapiToSource-win32 11422 ms 9481 ms 1.20
lotsOfClassesOneDir-componentSetCreate-win32 1965 ms 1536 ms 1.28
lotsOfClassesOneDir-sourceToMdapi-win32 23574 ms 19056 ms 1.24
lotsOfClassesOneDir-sourceToZip-win32 16940 ms 12816 ms 1.32
lotsOfClassesOneDir-mdapiToSource-win32 21021 ms 16921 ms 1.24

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.