1
1
import { runCommand } from "@oclif/test" ;
2
2
import fs from "fs" ;
3
- import { sep , posix } from "path" ;
3
+ import { sep , posix , join } from "path" ;
4
4
5
5
/**
6
6
* For the CLI tests to run, we need to run them in a Node environment with
7
7
* the NODE_OPTIONS=--experimental-vm-modules flag. This is because Jest ships
8
8
* with experimental support for ECMAScript Modules (ESM).
9
9
* See: https://jestjs.io/docs/ecmascript-modules
10
10
*/
11
+
11
12
describe ( "Oclif-provided Flags Tests" , ( ) => {
12
13
describe ( "--help flag" , ( ) => {
13
14
it ( "should provide the right help message" , async ( ) => {
@@ -89,14 +90,8 @@ describe("Config Prompt Tests", () => {
89
90
expect ( stderr ) . toContain ( "- Validating generated types" ) ;
90
91
expect ( stderr ) . toContain ( "✔ Validating generated types" ) ;
91
92
92
- expect (
93
- normalizeLineEndings (
94
- fs . readFileSync ( basicOutputPath , "utf-8" ) . toString ( )
95
- )
96
- ) . toEqual (
97
- normalizeLineEndings (
98
- fs . readFileSync ( basicSnapshotPath , "utf-8" ) . toString ( )
99
- )
93
+ expect ( readFileCrossEnv ( basicOutputPath ) ) . toEqual (
94
+ readFileCrossEnv ( basicSnapshotPath )
100
95
) ;
101
96
102
97
removeFile ( basicOutputPath ) ;
@@ -119,6 +114,19 @@ function normalizeLineEndings(content: string) {
119
114
return content . replace ( / \r \n / g, "\n" ) ; // Replace Windows (\r\n) with Unix (\n)
120
115
}
121
116
117
+ /**
118
+ * Angle brackets from inquirer prompts are not the same in Windows & Unix
119
+ * This function replaces them with a consistent character
120
+ */
122
121
function replaceAngleBracket ( content : string ) {
123
122
return content . replace ( / > / g, "❯" ) ;
124
123
}
124
+
125
+ /**
126
+ * Gets the string content of a file and normalizes a few things to make it comparable to snapshots
127
+ */
128
+ function readFileCrossEnv ( path : string ) {
129
+ return replaceAngleBracket (
130
+ normalizeLineEndings ( fs . readFileSync ( path , "utf-8" ) . toString ( ) )
131
+ ) ;
132
+ }
0 commit comments