9
9
10
10
var jscodeshift = require ( "jscodeshift" ) ;
11
11
var fs = require ( "fs" ) ;
12
+ var os = require ( "os" ) ;
12
13
var path = require ( "path" ) ;
13
14
var expect = require ( "chai" ) . expect ;
14
15
15
16
var newRuleFormatTransform = require ( "../../../lib/new-rule-format/new-rule-format" ) ;
16
17
18
+ /**
19
+ * Returns a new string with all the EOL markers from the string passed in
20
+ * replaced with the Operating System specific EOL marker.
21
+ * Useful for guaranteeing two transform outputs have the same EOL marker format.
22
+ *
23
+ * @param {string } input - the string which will have its EOL markers replaced
24
+ * @returns {string } a new string with all EOL markers replaced
25
+ * @private
26
+ */
27
+ function normalizeLineEndngs ( input ) {
28
+ return input . replace ( / ( \r \n | \n | \r ) / gm, os . EOL ) ;
29
+ }
30
+
17
31
/**
18
32
* Run a transform against a fixture file and compare results with expected output.
19
33
* The fixture file and expected output file should be named in the format
20
34
* `prefix.input.js` and `prefix.output.js` and should be located in the
21
35
* `tests/fixtures/` folder.
22
36
*
23
37
* @param {Function } transform - transform to test against
24
- * @param {String } transformFixturePrefix - prefix of fixture files
38
+ * @param {string } transformFixturePrefix - prefix of fixture files
25
39
* @returns {void }
40
+ * @private
26
41
*/
27
42
function testTransformWithFixture ( transform , transformFixturePrefix ) {
28
43
var fixtureDir = path . join ( __dirname , "../../fixtures/lib/new-rule-format" ) ;
@@ -42,9 +57,9 @@ function testTransformWithFixture(transform, transformFixturePrefix) {
42
57
) ;
43
58
44
59
expect (
45
- ( output || "" ) . trim ( )
60
+ normalizeLineEndngs ( ( output || "" ) . trim ( ) )
46
61
) . to . equal (
47
- expectedOutput . trim ( )
62
+ normalizeLineEndngs ( expectedOutput . trim ( ) )
48
63
) ;
49
64
} ) ;
50
65
}
@@ -57,8 +72,9 @@ function testTransformWithFixture(transform, transformFixturePrefix) {
57
72
* `tests/fixtures/` folder.
58
73
*
59
74
* @param {Function } transform - transform to test against
60
- * @param {String [] } fixtures - list of fixture prefixes
75
+ * @param {string [] } fixtures - list of fixture prefixes
61
76
* @returns {void }
77
+ * @private
62
78
*/
63
79
function testTransformWithFixtures ( transform , fixtures ) {
64
80
return fixtures . forEach ( function ( fixture ) {
0 commit comments