@@ -4,6 +4,7 @@ import fs from 'fs-extra';
4
4
import { prepare } from '../lib/prepare.js' ;
5
5
import * as contexts from './get-context.js' ;
6
6
import { replaceVersions } from '../lib/utils/replace-versions.js' ;
7
+ import { readDir , readFile } from './utils.js' ;
7
8
8
9
function getWorkDir ( suffix : string ) : string {
9
10
const files = fs . readdirSync ( os . tmpdir ( ) ) ;
@@ -40,11 +41,9 @@ describe('Package preparation - cusom work directory', () => {
40
41
} ,
41
42
contexts . prepareContext ,
42
43
) ;
43
- expect (
44
- fs
45
- . readFileSync ( path . join ( releasePath , 'plugin1' , 'plugin1.php' ) , 'utf8' )
46
- . toString ( ) ,
47
- ) . not . toMatch ( / 0 \. 0 \. 0 / ) ;
44
+ expect ( readFile ( releasePath , 'plugin1' , 'plugin1.php' ) ) . not . toMatch (
45
+ / 0 \. 0 \. 0 / ,
46
+ ) ;
48
47
} ) ;
49
48
50
49
it ( 'Should fail on invalid plugin version' , async ( ) => {
@@ -79,9 +78,10 @@ describe('Package preparation - cusom work directory', () => {
79
78
contexts . prepareContext ,
80
79
) ;
81
80
82
- const versions = fs . readFileSync (
83
- path . join ( getWorkDir ( workDir ) , 'plugin1/extra-versions.php' ) ,
84
- 'utf8' ,
81
+ const versions = readFile (
82
+ getWorkDir ( workDir ) ,
83
+ 'plugin1' ,
84
+ 'extra-versions.php' ,
85
85
) ;
86
86
87
87
expect ( versions ) . toMatch ( / 1 \. 0 \. 0 / ) ;
@@ -102,12 +102,9 @@ describe('Package preparation - cusom work directory', () => {
102
102
contexts . prepareContext ,
103
103
) ;
104
104
105
- const readme = fs . readFileSync (
106
- path . join ( releasePath , 'plugin-with-readme/readme.txt' ) ,
107
- 'utf8' ,
105
+ expect ( readFile ( releasePath , 'plugin-with-readme' , 'readme.txt' ) ) . toMatch (
106
+ / S t a b l e t a g : 1 \. 0 \. 0 / ,
108
107
) ;
109
-
110
- expect ( readme ) . toMatch ( / S t a b l e t a g : 1 \. 0 \. 0 / ) ;
111
108
} ) ;
112
109
113
110
it ( 'Should change the readme.txt version in the rootdir' , async ( ) => {
@@ -124,12 +121,9 @@ describe('Package preparation - cusom work directory', () => {
124
121
contexts . prepareContext ,
125
122
) ;
126
123
127
- const readme = fs . readFileSync (
128
- path . join ( getWorkDir ( workDir ) , 'root-readme/readme.txt' ) ,
129
- 'utf8' ,
124
+ expect ( readFile ( getWorkDir ( workDir ) , 'root-readme' , 'readme.txt' ) ) . toMatch (
125
+ / S t a b l e t a g : 1 \. 0 \. 0 / ,
130
126
) ;
131
-
132
- expect ( readme ) . toMatch ( / S t a b l e t a g : 1 \. 0 \. 0 / ) ;
133
127
} ) ;
134
128
135
129
it ( 'Should work with empty assets' , async ( ) => {
@@ -185,17 +179,10 @@ describe('Package preparation - default work directory', () => {
185
179
contexts . prepareContext ,
186
180
) ;
187
181
188
- const distFiles = fs . readdirSync ( path . join ( releasePath , 'dist-test' ) ) ;
189
- const vendorFiles = fs . readdirSync (
190
- path . join ( releasePath , 'dist-test' , 'vendor' ) ,
182
+ expect ( readDir ( true , releasePath , 'dist-test' ) ) . toStrictEqual (
183
+ new Set ( [ 'dist-test.php' , 'test1.php' , 'vendor' , 'vendor/composer.php' ] ) ,
191
184
) ;
192
- const versionExists = fs . existsSync ( path . join ( releasePath , 'VERSION' ) ) ;
193
-
194
- expect ( distFiles ) . toHaveLength ( 3 ) ;
195
- expect ( distFiles ) . toStrictEqual ( [ 'dist-test.php' , 'test1.php' , 'vendor' ] ) ;
196
- expect ( vendorFiles ) . toHaveLength ( 1 ) ;
197
- expect ( vendorFiles ) . toStrictEqual ( [ 'composer.php' ] ) ;
198
- expect ( versionExists ) . toBe ( false ) ;
185
+ expect ( fs . existsSync ( path . join ( releasePath , 'VERSION' ) ) ) . toBe ( false ) ;
199
186
} ) ;
200
187
201
188
it ( 'Should copy the assets files' , async ( ) => {
@@ -212,14 +199,7 @@ describe('Package preparation - default work directory', () => {
212
199
contexts . prepareContext ,
213
200
) ;
214
201
215
- const assets = new Set (
216
- fs . readdirSync ( path . join ( releasePath , 'assets' ) , {
217
- recursive : true ,
218
- } ) as string [ ] ,
219
- ) ;
220
-
221
- expect ( [ ...assets ] ) . toHaveLength ( 6 ) ;
222
- expect ( assets ) . toEqual (
202
+ expect ( readDir ( true , releasePath , 'assets' ) ) . toEqual (
223
203
new Set ( [
224
204
'blueprints' ,
225
205
'blueprints/blueprint.json' ,
0 commit comments