44// License text available at https://opensource.org/licenses/MIT
55
66import { TestSandbox , expect } from '../..' ;
7- import { existsSync , readFile as readFile_ } from 'fs' ;
87import { resolve } from 'path' ;
98import { createHash } from 'crypto' ;
109import * as util from 'util' ;
11- const promisify = util . promisify || require ( 'util.promisify/implementation' ) ;
12- const rimraf = require ( 'rimraf' ) ;
13- const readFile = promisify ( readFile_ ) ;
10+ import { remove , pathExists , readFile } from 'fs-extra' ;
1411
1512describe ( 'TestSandbox integration tests' , ( ) => {
1613 let sandbox : TestSandbox ;
@@ -28,43 +25,43 @@ describe('TestSandbox integration tests', () => {
2825 beforeEach ( givenPath ) ;
2926 afterEach ( deleteSandbox ) ;
3027
31- it ( 'returns path of sandbox and it exists' , ( ) => {
28+ it ( 'returns path of sandbox and it exists' , async ( ) => {
3229 expect ( path ) . to . be . a . String ( ) ;
33- expect ( existsSync ( path ) ) . to . be . True ( ) ;
30+ expect ( await pathExists ( path ) ) . to . be . True ( ) ;
3431 } ) ;
3532
3633 it ( 'creates a directory in the sandbox' , async ( ) => {
3734 const dir = 'controllers' ;
3835 await sandbox . mkdir ( dir ) ;
39- expect ( existsSync ( resolve ( path , dir ) ) ) . to . be . True ( ) ;
36+ expect ( await pathExists ( resolve ( path , dir ) ) ) . to . be . True ( ) ;
4037 } ) ;
4138
4239 it ( 'copies a file to the sandbox' , async ( ) => {
43- await sandbox . copy ( COPY_FILE_PATH ) ;
44- expect ( existsSync ( resolve ( path , COPY_FILE ) ) ) . to . be . True ( ) ;
40+ await sandbox . copyFile ( COPY_FILE_PATH ) ;
41+ expect ( await pathExists ( resolve ( path , COPY_FILE ) ) ) . to . be . True ( ) ;
4542 await compareFiles ( resolve ( path , COPY_FILE ) ) ;
4643 } ) ;
4744
4845 it ( 'copies and renames the file to the sandbox' , async ( ) => {
4946 const rename = 'copy.me.js' ;
50- await sandbox . copy ( COPY_FILE_PATH , rename ) ;
51- expect ( existsSync ( resolve ( path , COPY_FILE ) ) ) . to . be . False ( ) ;
52- expect ( existsSync ( resolve ( path , rename ) ) ) . to . be . True ( ) ;
47+ await sandbox . copyFile ( COPY_FILE_PATH , rename ) ;
48+ expect ( await pathExists ( resolve ( path , COPY_FILE ) ) ) . to . be . False ( ) ;
49+ expect ( await pathExists ( resolve ( path , rename ) ) ) . to . be . True ( ) ;
5350 await compareFiles ( resolve ( path , rename ) ) ;
5451 } ) ;
5552
5653 it ( 'copies file to a directory' , async ( ) => {
5754 const dir = 'test' ;
5855 await sandbox . mkdir ( dir ) ;
5956 const rename = `${ dir } /${ COPY_FILE } ` ;
60- await sandbox . copy ( COPY_FILE_PATH , rename ) ;
61- expect ( existsSync ( resolve ( path , rename ) ) ) . to . be . True ( ) ;
57+ await sandbox . copyFile ( COPY_FILE_PATH , rename ) ;
58+ expect ( await pathExists ( resolve ( path , rename ) ) ) . to . be . True ( ) ;
6259 await compareFiles ( resolve ( path , rename ) ) ;
6360 } ) ;
6461
6562 it ( 'deletes the test sandbox' , async ( ) => {
6663 await sandbox . delete ( ) ;
67- expect ( existsSync ( path ) ) . to . be . False ( ) ;
64+ expect ( await pathExists ( path ) ) . to . be . False ( ) ;
6865 } ) ;
6966
7067 describe ( 'after deleting sandbox' , ( ) => {
@@ -82,7 +79,7 @@ describe('TestSandbox integration tests', () => {
8279 } ) ;
8380
8481 it ( 'throws an error when trying to call copy()' , async ( ) => {
85- await expect ( sandbox . copy ( COPY_FILE_PATH ) ) . to . be . rejectedWith ( ERR ) ;
82+ await expect ( sandbox . copyFile ( COPY_FILE_PATH ) ) . to . be . rejectedWith ( ERR ) ;
8683 } ) ;
8784
8885 it ( 'throws an error when trying to call reset()' , async ( ) => {
@@ -111,13 +108,9 @@ describe('TestSandbox integration tests', () => {
111108 path = sandbox . getPath ( ) ;
112109 }
113110
114- function deleteSandbox ( ) {
115- if ( ! existsSync ( path ) ) return ;
116- try {
117- rimraf . sync ( sandbox . getPath ( ) ) ;
118- } catch ( err ) {
119- console . log ( `Failed to delete sandbox because: ${ err } ` ) ;
120- }
111+ async function deleteSandbox ( ) {
112+ if ( ! await pathExists ( path ) ) return ;
113+ await remove ( sandbox . getPath ( ) ) ;
121114 }
122115
123116 async function getCopyFileContents ( ) {
0 commit comments