Skip to content

Commit 5c1e875

Browse files
add pathTransform test
1 parent 2a7dd65 commit 5c1e875

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/cli.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ And the user wants the outputs to be in MultiSchema/Out, then this code will be
102102
MultiSchema/Out/bar/fuzz/c.json
103103
MultiSchema/Out/bar/d.json
104104
*/
105-
function pathTransform(o: string, i: string): string {
105+
export function pathTransform(o: string, i: string): string {
106106
const outPathList = o.split('/')
107107
const inPathList = i.split('/')
108108

@@ -123,15 +123,6 @@ async function processDir(argIn: string, argOut: string | undefined, argv: Parti
123123
processFile(file, argOut, argv)
124124
} else {
125125
let outPath = pathTransform(argOut, file)
126-
// const outPathList = argOut.split('/')
127-
// const inPathList = file.split('/')
128-
129-
// const intersection = outPathList.filter(x => inPathList.includes(x))
130-
// const difference = outPathList
131-
// .filter(x => !inPathList.includes(x))
132-
// .concat(inPathList.filter(x => !outPathList.includes(x)))
133-
134-
// let outPath = join(...intersection, ...difference)
135126
if (!isDir(dirname(outPath))) {
136127
_mkdirp.sync(dirname(outPath))
137128
}

test/testCLI.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {serial as test} from 'ava'
22
import {execSync} from 'child_process'
33
import {readFileSync, unlinkSync, readdirSync, rmdirSync, existsSync, lstatSync} from 'fs'
44
import {resolve, join} from 'path'
5+
import {pathTransform} from '../src/cli'
56

67
export function run() {
78
test('pipe in, pipe out', t => {
@@ -113,6 +114,15 @@ export function run() {
113114
})
114115
rmdirSync('./test/resources/MultiSchema2/out', {recursive: true})
115116
})
117+
118+
test('validate pathTransform function', t => {
119+
const inputPaths = ['MultiSchema/foo/a.json', 'MultiSchema/bar/fuzz/c.json', 'MultiSchema/bar/d.json']
120+
const outputPath = 'MultiSchema/Out'
121+
122+
t.is(pathTransform(outputPath, inputPaths[0]), 'MultiSchema/Out/foo/a.json')
123+
t.is(pathTransform(outputPath, inputPaths[1]), 'MultiSchema/Out/bar/d.json')
124+
t.is(pathTransform(outputPath, inputPaths[2]), 'MultiSchema/Out/bar/fuzz/c.json')
125+
})
116126
}
117127

118128
function getPaths(path: string, paths: string[] = []) {

0 commit comments

Comments
 (0)