Skip to content

Commit b2b4b53

Browse files
authored
Merge pull request #71 from kadamwhite/convert-to-jest
Convert test suites to use jest instead of nyc, mocha, and chai
2 parents 546b1f5 + 3eaf568 commit b2b4b53

File tree

5 files changed

+91
-122
lines changed

5 files changed

+91
-122
lines changed

lib/patch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
var grunt = require( 'grunt' ),
22
_ = require( 'underscore' );
33

4+
_.str = _.str = require( 'underscore.string' );
5+
_.mixin( _.str.exports() );
6+
47
module.exports = {
58
isAb: function( diff ) {
69
var ab = false;

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@
2121
"node": ">= 8.9.3"
2222
},
2323
"scripts": {
24-
"test": "mocha",
25-
"test:coverage": "nyc mocha",
26-
"test:watch": "mocha -w",
24+
"test": "jest",
25+
"test:coverage": "jest --coverage",
26+
"test:watch": "jest --watch",
2727
"lint": "eslint . --ignore-path coverage",
2828
"lint:fix": "eslint . --fix"
2929
},
30+
"jest": {
31+
"testMatch": [
32+
"**/test/**/*.js"
33+
]
34+
},
3035
"devDependencies": {
31-
"chai": "^4.1.2",
3236
"eslint": "^4.17.0",
3337
"eslint-config-wordpress": "^2.0.0",
34-
"mocha": "^5.0.0",
35-
"nyc": "^11.4.1"
38+
"jest": "^24.5.0"
3639
},
3740
"dependencies": {
3841
"grunt": "^1.0.2",

test/patch_wordpress_test.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,28 @@
33
var grunt = require( 'grunt' ),
44
patch = require( '../lib/patch.js' ),
55
url = require( 'url' ),
6-
expect = require( 'chai' ).expect,
76
trac = require( '../lib/trac.js' ),
87
mapOldToNewFilePath = require( '../lib/map_old_to_new_file_path.js' );
98

109
describe( 'grunt_patch_wordpress', function() {
1110
describe( 'sanity checks', function() {
12-
it( 'a is a', function( done ) {
13-
expect( 'a' ).to.equal( 'a' );
14-
done();
11+
it( 'a is a', function() {
12+
expect( 'a' ).toEqual( 'a' );
1513
});
1614

1715
});
1816

19-
it( 'convertToRaw converts urls', function( done ) {
20-
expect( trac.convertToRaw ( url.parse( 'https://core.trac.wordpress.org/attachment/ticket/26700/26700.diff' ) ) ).to.equal( 'https://core.trac.wordpress.org/raw-attachment/ticket/26700/26700.diff' );
21-
done();
17+
it( 'convertToRaw converts urls', function() {
18+
expect( trac.convertToRaw ( url.parse( 'https://core.trac.wordpress.org/attachment/ticket/26700/26700.diff' ) ) ).toEqual( 'https://core.trac.wordpress.org/raw-attachment/ticket/26700/26700.diff' );
2219
});
2320

2421
describe( 'Level Calculator', function() {
2522

2623
// @TODO: Find alot of patches to use here
2724

28-
it ( '26602.2.diff is 0', function( done ) {
25+
it ( '26602.2.diff is 0', function() {
2926
var file = grunt.file.read( 'test/fixtures/26602.2.diff' );
30-
expect( patch.isAb( file ) ).to.be.false;
31-
done();
27+
expect( patch.isAb( file ) ).toBe( false );
3228
});
3329
});
3430

@@ -39,7 +35,7 @@ describe( 'grunt_patch_wordpress', function() {
3935
};
4036

4137
describe( 'old to new', function() {
42-
before( function() {
38+
beforeAll( function() {
4339
grunt.file.copy( './test/fixtures/patch_wordpress_1.diff', './test/tmp/patch_wordpress_1_copy.diff' );
4440
mapOldToNewFilePath( './test/tmp/patch_wordpress_1_copy.diff', fileMappings );
4541
});
@@ -48,16 +44,16 @@ describe( 'grunt_patch_wordpress', function() {
4844
var expected = grunt.file.read( './test/expected/patch_wordpress_1.diff' );
4945
var actual = grunt.file.read( './test/tmp/patch_wordpress_1_copy.diff' );
5046

51-
expect( actual ).to.equal( expected );
47+
expect( actual ).toEqual( expected );
5248
});
5349

54-
after( function() {
50+
afterAll( function() {
5551
grunt.file.delete( './test/tmp/patch_wordpress_1_copy.diff' );
5652
});
5753
});
5854

5955
describe( 'new stay unchanged', function() {
60-
before( function() {
56+
beforeAll( function() {
6157
grunt.file.copy( './test/fixtures/patch_wordpress_2.diff', './test/tmp/patch_wordpress_2_copy.diff' );
6258
mapOldToNewFilePath( './test/tmp/patch_wordpress_2_copy.diff', fileMappings );
6359
});
@@ -66,16 +62,16 @@ describe( 'grunt_patch_wordpress', function() {
6662
var expected = grunt.file.read( './test/expected/patch_wordpress_2.diff' );
6763
var actual = grunt.file.read( './test/tmp/patch_wordpress_2_copy.diff' );
6864

69-
expect( actual ).to.equal( expected );
65+
expect( actual ).toEqual( expected );
7066
});
7167

72-
after( function() {
68+
afterAll( function() {
7369
grunt.file.delete( './test/tmp/patch_wordpress_2_copy.diff' );
7470
});
7571
});
7672

7773
describe( 'unknown stay unchanged', function() {
78-
before( function() {
74+
beforeAll( function() {
7975
grunt.file.copy( './test/fixtures/patch_wordpress_3.diff', './test/tmp/patch_wordpress_3_copy.diff' );
8076
mapOldToNewFilePath( './test/tmp/patch_wordpress_3_copy.diff', fileMappings );
8177
});
@@ -84,16 +80,16 @@ describe( 'grunt_patch_wordpress', function() {
8480
var expected = grunt.file.read( './test/expected/patch_wordpress_3.diff' );
8581
var actual = grunt.file.read( './test/tmp/patch_wordpress_3_copy.diff' );
8682

87-
expect( actual ).to.equal( expected );
83+
expect( actual ).toEqual( expected );
8884
});
8985

90-
after( function() {
86+
afterAll( function() {
9187
grunt.file.delete( './test/tmp/patch_wordpress_3_copy.diff' );
9288
});
9389
});
9490

9591
describe( 'new stay unchanged, old to new', function() {
96-
before( function() {
92+
beforeAll( function() {
9793
grunt.file.copy( './test/fixtures/patch_wordpress_4.diff', './test/tmp/patch_wordpress_4_copy.diff' );
9894
mapOldToNewFilePath( './test/tmp/patch_wordpress_4_copy.diff', fileMappings );
9995
});
@@ -103,16 +99,16 @@ describe( 'grunt_patch_wordpress', function() {
10399
var expected = grunt.file.read( './test/expected/patch_wordpress_4.diff' );
104100
var actual = grunt.file.read( './test/tmp/patch_wordpress_4_copy.diff' );
105101

106-
expect( actual ).to.equal( expected );
102+
expect( actual ).toEqual( expected );
107103
});
108104

109-
after( function() {
105+
afterAll( function() {
110106
grunt.file.delete( './test/tmp/patch_wordpress_4_copy.diff' );
111107
});
112108
});
113109

114110
describe( 'new and unknown stay unchanged', function() {
115-
before( function() {
111+
beforeAll( function() {
116112
grunt.file.copy( './test/fixtures/patch_wordpress_5.diff', './test/tmp/patch_wordpress_5_copy.diff' );
117113
mapOldToNewFilePath( './test/tmp/patch_wordpress_5_copy.diff', fileMappings );
118114
});
@@ -122,16 +118,16 @@ describe( 'grunt_patch_wordpress', function() {
122118
var expected = grunt.file.read( './test/expected/patch_wordpress_5.diff' );
123119
var actual = grunt.file.read( './test/tmp/patch_wordpress_5_copy.diff' );
124120

125-
expect( actual ).to.equal( expected );
121+
expect( actual ).toEqual( expected );
126122
});
127123

128-
after( function() {
124+
afterAll( function() {
129125
grunt.file.delete( './test/tmp/patch_wordpress_5_copy.diff' );
130126
});
131127
});
132128

133129
describe( 'new and unknown stay unchanged, old to new', function() {
134-
before( function() {
130+
beforeAll( function() {
135131
grunt.file.copy( './test/fixtures/patch_wordpress_6.diff', './test/tmp/patch_wordpress_6_copy.diff' );
136132
mapOldToNewFilePath( './test/tmp/patch_wordpress_6_copy.diff', fileMappings );
137133
});
@@ -140,17 +136,17 @@ describe( 'grunt_patch_wordpress', function() {
140136
var expected = grunt.file.read( './test/expected/patch_wordpress_6.diff' );
141137
var actual = grunt.file.read( './test/tmp/patch_wordpress_6_copy.diff' );
142138

143-
expect( actual ).to.equal( expected );
139+
expect( actual ).toEqual( expected );
144140
});
145141

146-
after( function() {
142+
afterAll( function() {
147143
grunt.file.delete( './test/tmp/patch_wordpress_6_copy.diff' );
148144
});
149145
});
150146

151147
// There is no src folder in core.
152148
describe( 'non-src old to new', function() {
153-
before( function() {
149+
beforeAll( function() {
154150
grunt.file.copy( './test/fixtures/patch_wordpress_7.diff', './test/tmp/patch_wordpress_7_copy.diff' );
155151
mapOldToNewFilePath( './test/tmp/patch_wordpress_7_copy.diff', fileMappings );
156152
});
@@ -159,10 +155,10 @@ describe( 'grunt_patch_wordpress', function() {
159155
var expected = grunt.file.read( './test/expected/patch_wordpress_7.diff' );
160156
var actual = grunt.file.read( './test/tmp/patch_wordpress_7_copy.diff' );
161157

162-
expect( actual ).to.equal( expected );
158+
expect( actual ).toEqual( expected );
163159
});
164160

165-
after( function() {
161+
afterAll( function() {
166162
grunt.file.delete( './test/tmp/patch_wordpress_7_copy.diff' );
167163
});
168164
});

test/patches.js

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var grunt = require( 'grunt' ),
2-
expect = require( 'chai' ).expect,
32
patch = require( '../lib/patch.js' ),
43
coreGit = grunt.file.read ( 'test/fixtures/core.git.diff' ),
54
coreSvn = grunt.file.read ( 'test/fixtures/core.svn.diff' ),
@@ -18,98 +17,73 @@ var grunt = require( 'grunt' ),
1817

1918
describe( 'Patch helpers', function() {
2019

21-
it( 'git a/b diffs should not automatticaly trigger moving to src', function( done ) {
22-
expect( patch.moveToSrc( abyes ) ).to.not.be.true;
23-
24-
done();
20+
it( 'git a/b diffs should not automatticaly trigger moving to src', function() {
21+
expect( patch.moveToSrc( abyes ) ).not.toBe( true );
2522
});
2623

27-
it( 'tests diffs should always be applied in the root of the checkout', function( done ) {
28-
29-
expect( patch.moveToSrc( testsGit ) ).to.not.be.true;
30-
expect( patch.moveToSrc( testsSvn ) ).to.not.be.true;
24+
it( 'tests diffs should always be applied in the root of the checkout', function() {
3125

32-
done();
26+
expect( patch.moveToSrc( testsGit ) ).not.toBe( true );
27+
expect( patch.moveToSrc( testsSvn ) ).not.toBe( true );
3328
});
3429

35-
it( 'dev.git diffs should always be applied in the root of the checkout', function( done ) {
30+
it( 'dev.git diffs should always be applied in the root of the checkout', function() {
3631

37-
expect( patch.moveToSrc( developGit ) ).to.not.be.true;
38-
expect( patch.moveToSrc( developIndexGit ) ).to.not.be.true;
39-
40-
done();
32+
expect( patch.moveToSrc( developGit ) ).not.toBe( true );
33+
expect( patch.moveToSrc( developIndexGit ) ).not.toBe( true );
4134
});
4235

43-
it( 'dev.svn diffs should always be applied in the root of the checkout', function( done ) {
44-
45-
expect( patch.moveToSrc( developSvn ) ).to.not.be.true;
46-
expect( patch.moveToSrc( developIndexSvn ) ).to.not.be.true;
36+
it( 'dev.svn diffs should always be applied in the root of the checkout', function() {
4737

48-
done();
38+
expect( patch.moveToSrc( developSvn ) ).not.toBe( true );
39+
expect( patch.moveToSrc( developIndexSvn ) ).not.toBe( true );
4940
});
5041

51-
it( 'core.git.wordpress.org diffs should always be applied in the svn folder', function( done ) {
42+
it( 'core.git.wordpress.org diffs should always be applied in the svn folder', function() {
5243

53-
expect( patch.moveToSrc( coreGit ) ).to.be.true;
54-
55-
done();
44+
expect( patch.moveToSrc( coreGit ) ).toBe( true );
5645
});
5746

58-
it( 'core.svn.wordpress.org diffs should always be applied in the svn folder', function( done ) {
59-
60-
expect( patch.moveToSrc( coreSvn ) ).to.be.true;
47+
it( 'core.svn.wordpress.org diffs should always be applied in the svn folder', function() {
6148

62-
done();
49+
expect( patch.moveToSrc( coreSvn ) ).toBe( true );
6350
});
6451

65-
it( 'core.svn.wordpress.org diffs from trunk should always be applied in the src folder', function( done ) {
66-
67-
expect( patch.moveToSrc( coreTrunkSvn ) ).to.be.true;
68-
expect( patch.isAb( coreTrunkSvn ) ).to.be.true;
52+
it( 'core.svn.wordpress.org diffs from trunk should always be applied in the src folder', function() {
6953

70-
done();
54+
expect( patch.moveToSrc( coreTrunkSvn ) ).toBe( true );
55+
expect( patch.isAb( coreTrunkSvn ) ).toBe( true );
7156
});
7257

73-
it( 'index.php should always be applied in the src folder', function( done ) {
74-
75-
expect( patch.moveToSrc( coreIndexSvn ) ).to.be.true;
76-
expect( patch.moveToSrc( coreIndexGit ) ).to.be.true;
77-
78-
done();
79-
58+
it( 'index.php should always be applied in the src folder', function() {
59+
expect( patch.moveToSrc( coreIndexSvn ) ).toBe( true );
60+
expect( patch.moveToSrc( coreIndexGit ) ).toBe( true );
8061
});
8162

82-
it( 'wp-config-sample.php should always be applied in the root folder', function( done ) {
83-
expect( patch.moveToSrc( developSampleSvn ) ).to.not.be.true;
84-
expect( patch.moveToSrc( developSampleGit ) ).to.not.be.true;
85-
86-
done();
87-
63+
it( 'wp-config-sample.php should always be applied in the root folder', function() {
64+
expect( patch.moveToSrc( developSampleSvn ) ).not.toBe( true );
65+
expect( patch.moveToSrc( developSampleGit ) ).not.toBe( true );
8866
});
8967

90-
it ( 'isAb should return true on patches with a/ b/ style', function( done ) {
91-
92-
expect( patch.isAb( abyes ) ).to.be.true;
68+
it ( 'isAb should return true on patches with a/ b/ style', function() {
9369

94-
done();
70+
expect( patch.isAb( abyes ) ).toBe( true );
9571
});
9672

97-
it ( 'isAb should return false on patches without a/ b/ style', function( done ) {
98-
99-
expect( patch.isAb( developSampleGit ) ).to.not.be.true;
100-
expect( patch.isAb( developSampleSvn ) ).to.not.be.true;
101-
expect( patch.isAb( coreIndexGit ) ).to.not.be.true;
102-
expect( patch.isAb( coreIndexSvn ) ).to.not.be.true;
103-
expect( patch.isAb( coreGit ) ).to.not.be.true;
104-
expect( patch.isAb( coreSvn ) ).to.not.be.true;
105-
expect( patch.isAb( developGit ) ).to.not.be.true;
106-
expect( patch.isAb( developSvn ) ).to.not.be.true;
107-
expect( patch.isAb( developIndexGit ) ).to.not.be.true;
108-
expect( patch.isAb( developIndexSvn ) ).to.not.be.true;
109-
expect( patch.isAb( testsGit ) ).to.not.be.true;
110-
expect( patch.isAb( testsSvn ) ).to.not.be.true;
111-
112-
done();
73+
it ( 'isAb should return false on patches without a/ b/ style', function() {
74+
75+
expect( patch.isAb( developSampleGit ) ).not.toBe( true );
76+
expect( patch.isAb( developSampleSvn ) ).not.toBe( true );
77+
expect( patch.isAb( coreIndexGit ) ).not.toBe( true );
78+
expect( patch.isAb( coreIndexSvn ) ).not.toBe( true );
79+
expect( patch.isAb( coreGit ) ).not.toBe( true );
80+
expect( patch.isAb( coreSvn ) ).not.toBe( true );
81+
expect( patch.isAb( developGit ) ).not.toBe( true );
82+
expect( patch.isAb( developSvn ) ).not.toBe( true );
83+
expect( patch.isAb( developIndexGit ) ).not.toBe( true );
84+
expect( patch.isAb( developIndexSvn ) ).not.toBe( true );
85+
expect( patch.isAb( testsGit ) ).not.toBe( true );
86+
expect( patch.isAb( testsSvn ) ).not.toBe( true );
11387
});
11488

11589
});

0 commit comments

Comments
 (0)