@@ -4,6 +4,7 @@ import fs from 'fs-extra';
44import { prepare } from '../lib/prepare.js' ;
55import * as contexts from './get-context.js' ;
66import { replaceVersions } from '../lib/utils/replace-versions.js' ;
7+ import { readDir , readFile } from './utils.js' ;
78
89function getWorkDir ( suffix : string ) : string {
910 const files = fs . readdirSync ( os . tmpdir ( ) ) ;
@@ -40,11 +41,9 @@ describe('Package preparation - cusom work directory', () => {
4041 } ,
4142 contexts . prepareContext ,
4243 ) ;
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+ ) ;
4847 } ) ;
4948
5049 it ( 'Should fail on invalid plugin version' , async ( ) => {
@@ -79,9 +78,10 @@ describe('Package preparation - cusom work directory', () => {
7978 contexts . prepareContext ,
8079 ) ;
8180
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' ,
8585 ) ;
8686
8787 expect ( versions ) . toMatch ( / 1 \. 0 \. 0 / ) ;
@@ -102,12 +102,9 @@ describe('Package preparation - cusom work directory', () => {
102102 contexts . prepareContext ,
103103 ) ;
104104
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 / ,
108107 ) ;
109-
110- expect ( readme ) . toMatch ( / S t a b l e t a g : 1 \. 0 \. 0 / ) ;
111108 } ) ;
112109
113110 it ( 'Should change the readme.txt version in the rootdir' , async ( ) => {
@@ -124,12 +121,9 @@ describe('Package preparation - cusom work directory', () => {
124121 contexts . prepareContext ,
125122 ) ;
126123
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 / ,
130126 ) ;
131-
132- expect ( readme ) . toMatch ( / S t a b l e t a g : 1 \. 0 \. 0 / ) ;
133127 } ) ;
134128
135129 it ( 'Should work with empty assets' , async ( ) => {
@@ -185,17 +179,10 @@ describe('Package preparation - default work directory', () => {
185179 contexts . prepareContext ,
186180 ) ;
187181
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' ] ) ,
191184 ) ;
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 ) ;
199186 } ) ;
200187
201188 it ( 'Should copy the assets files' , async ( ) => {
@@ -212,14 +199,7 @@ describe('Package preparation - default work directory', () => {
212199 contexts . prepareContext ,
213200 ) ;
214201
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 (
223203 new Set ( [
224204 'blueprints' ,
225205 'blueprints/blueprint.json' ,
0 commit comments