Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 0df0664

Browse files
authored
Merge pull request bcherny#464 from s-weigand/cross-platform-tests-rebased
🧪 Cross platform tests (follow up)
2 parents 9212a77 + 8fa728e commit 0df0664

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {deburr, isPlainObject, trim, upperFirst} from 'lodash'
2-
import {basename, dirname, extname, join, normalize, sep} from 'path'
2+
import {basename, dirname, extname, normalize, sep, posix} from 'path'
33
import {JSONSchema, LinkedJSONSchema, Parent} from './types/JSONSchema'
44

55
// TODO: pull out into a separate package
@@ -274,7 +274,7 @@ export function pathTransform(outputPath: string, inputPath: string, filePath: s
274274
const filePathList = dirname(normalize(filePath)).split(sep)
275275
const filePathRel = filePathList.filter((f, i) => f !== inPathList[i])
276276

277-
return join(normalize(outputPath), ...filePathRel)
277+
return posix.join(posix.normalize(outputPath), ...filePathRel)
278278
}
279279

280280
/**

test/__snapshots__/test/test.ts.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -12044,7 +12044,7 @@ Generated by [AVA](https://avajs.dev).
1204412044

1204512045
> Snapshot 1
1204612046
12047-
'test/resources/MultiSchema2/out/bar/SameDirName/MultiSchema2/e.d.ts'
12047+
'test/resources/MultiSchema2/out/bar/b.d.ts'
1204812048

1204912049
> Snapshot 2
1205012050
@@ -12055,12 +12055,16 @@ Generated by [AVA](https://avajs.dev).
1205512055
* and run json-schema-to-typescript to regenerate this file.␊
1205612056
*/␊
1205712057
12058-
export type ESchema = string;␊
12058+
export interface BSchema {␊
12059+
x?: string;␊
12060+
y: number;␊
12061+
[k: string]: unknown;␊
12062+
}␊
1205912063
`
1206012064

1206112065
> Snapshot 3
1206212066
12063-
'test/resources/MultiSchema2/out/bar/b.d.ts'
12067+
'test/resources/MultiSchema2/out/bar/SameDirName/MultiSchema2/e.d.ts'
1206412068

1206512069
> Snapshot 4
1206612070
@@ -12071,11 +12075,7 @@ Generated by [AVA](https://avajs.dev).
1207112075
* and run json-schema-to-typescript to regenerate this file.␊
1207212076
*/␊
1207312077
12074-
export interface BSchema {␊
12075-
x?: string;␊
12076-
y: number;␊
12077-
[k: string]: unknown;␊
12078-
}␊
12078+
export type ESchema = string;␊
1207912079
`
1208012080

1208112081
> Snapshot 5

test/__snapshots__/test/test.ts.snap

0 Bytes
Binary file not shown.

test/testCLI.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava'
22
import {execSync} from 'child_process'
33
import {readFileSync, unlinkSync, readdirSync, existsSync, lstatSync} from 'fs'
4-
import {resolve, join} from 'path'
4+
import {resolve, posix} from 'path'
55
import rimraf = require('rimraf')
66

77
export function run() {
@@ -84,7 +84,7 @@ export function run() {
8484
})
8585

8686
test('files in (-i), files out (-o)', t => {
87-
execSync("node dist/src/cli.js -i './test/resources/MultiSchema/**/*.json' -o ./test/resources/MultiSchema/out")
87+
execSync(`node dist/src/cli.js -i "./test/resources/MultiSchema/**/*.json" -o ./test/resources/MultiSchema/out`)
8888

8989
readdirSync('./test/resources/MultiSchema/out').forEach(f => {
9090
const path = `./test/resources/MultiSchema/out/${f}`
@@ -96,12 +96,12 @@ export function run() {
9696
})
9797

9898
test('files in (-i), pipe out', t => {
99-
t.snapshot(execSync("node dist/src/cli.js -i './test/resources/MultiSchema/**/*.json'").toString())
99+
t.snapshot(execSync(`node dist/src/cli.js -i "./test/resources/MultiSchema/**/*.json"`).toString())
100100
})
101101

102102
test('files in (-i), files out (-o) nested dir does not exist', t => {
103103
execSync(
104-
"node dist/src/cli.js -i './test/resources/MultiSchema/**/*.json' -o ./test/resources/MultiSchema/foo/bar/out"
104+
`node dist/src/cli.js -i "./test/resources/MultiSchema/**/*.json" -o ./test/resources/MultiSchema/foo/bar/out`
105105
)
106106
readdirSync('./test/resources/MultiSchema/foo/bar/out').forEach(f => {
107107
const path = `./test/resources/MultiSchema/foo/bar/out/${f}`
@@ -114,7 +114,7 @@ export function run() {
114114

115115
test('files in (-i), files out (-o) matching nested dir', t => {
116116
execSync(
117-
"node dist/src/cli.js -i './test/resources/../../test/resources/MultiSchema2/' -o ./test/resources/MultiSchema2/out"
117+
`node dist/src/cli.js -i "./test/resources/../../test/resources/MultiSchema2/" -o ./test/resources/MultiSchema2/out`
118118
)
119119
getPaths('./test/resources/MultiSchema2/out').forEach(file => {
120120
t.snapshot(file)
@@ -127,10 +127,11 @@ export function run() {
127127

128128
function getPaths(path: string, paths: string[] = []) {
129129
if (existsSync(path) && lstatSync(path).isDirectory()) {
130-
readdirSync(resolve(path)).forEach(item => getPaths(join(path, item), paths))
130+
readdirSync(resolve(path)).forEach(item => getPaths(posix.join(posix.normalize(path), item), paths))
131131
} else {
132132
paths.push(path)
133133
}
134134

135-
return paths
135+
// sort paths to ensure a stable order across environments
136+
return paths.sort((a, b) => a.localeCompare(b))
136137
}

0 commit comments

Comments
 (0)