14
14
* limitations under the License.
15
15
*
16
16
*/
17
- import { describe , expect , it } from '@jest/globals'
18
17
import * as core from '../../../src/core/index.mjs'
19
18
import { SoloError , IllegalArgumentError , MissingArgumentError } from '../../../src/core/errors.mjs'
20
19
import os from 'os'
@@ -26,72 +25,72 @@ describe('Zippy', () => {
26
25
const zippy = new Zippy ( testLogger )
27
26
28
27
describe ( 'unzip' , ( ) => {
29
- it ( 'should fail if source file is missing' , async ( ) => {
28
+ it ( 'should fail if source file is missing' , ( ) => {
30
29
expect . assertions ( 1 )
31
- await expect ( zippy . unzip ( '' , '' ) ) . rejects . toThrow ( MissingArgumentError )
30
+ expect ( ( ) => { zippy . unzip ( '' , '' ) } ) . toThrow ( MissingArgumentError )
32
31
} )
33
32
34
- it ( 'should fail if destination file is missing' , async ( ) => {
33
+ it ( 'should fail if destination file is missing' , ( ) => {
35
34
expect . assertions ( 1 )
36
- await expect ( zippy . unzip ( '' , '' ) ) . rejects . toThrow ( MissingArgumentError )
35
+ expect ( ( ) => { zippy . unzip ( '' , '' ) } ) . toThrow ( MissingArgumentError )
37
36
} )
38
37
39
- it ( 'should fail if source file is invalid' , async ( ) => {
38
+ it ( 'should fail if source file is invalid' , ( ) => {
40
39
expect . assertions ( 1 )
41
- await expect ( zippy . unzip ( '/INVALID' , os . tmpdir ( ) ) ) . rejects . toThrow ( IllegalArgumentError )
40
+ expect ( ( ) => { zippy . unzip ( '/INVALID' , os . tmpdir ( ) ) } ) . toThrow ( IllegalArgumentError )
42
41
} )
43
42
44
- it ( 'should fail for a directory' , async ( ) => {
43
+ it ( 'should fail for a directory' , ( ) => {
45
44
expect . assertions ( 1 )
46
- await expect ( zippy . unzip ( 'test/data' , os . tmpdir ( ) ) ) . rejects . toThrow ( SoloError )
45
+ expect ( ( ) => { zippy . unzip ( 'test/data' , os . tmpdir ( ) ) } ) . toThrow ( SoloError )
47
46
} )
48
47
49
- it ( 'should fail for a non-zip file' , async ( ) => {
48
+ it ( 'should fail for a non-zip file' , ( ) => {
50
49
expect . assertions ( 1 )
51
- await expect ( zippy . unzip ( 'test/data/test.txt' , os . tmpdir ( ) ) ) . rejects . toThrow ( SoloError )
50
+ expect ( ( ) => { zippy . unzip ( 'test/data/test.txt' , os . tmpdir ( ) ) } ) . toThrow ( SoloError )
52
51
} )
53
52
54
53
it ( 'should succeed for valid inputs' , async ( ) => {
55
54
const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'installer-' ) )
56
55
const zipFile = `${ tmpDir } /test.zip`
57
56
const unzippedFile = `${ tmpDir } /unzipped`
58
57
await expect ( zippy . zip ( 'test/data/.empty' , zipFile ) ) . resolves . toBe ( zipFile )
59
- await expect ( zippy . unzip ( zipFile , unzippedFile , true ) ) . resolves . toBe ( unzippedFile )
58
+ expect ( zippy . unzip ( zipFile , unzippedFile , true ) ) . toBe ( unzippedFile )
60
59
fs . rmSync ( tmpDir , { recursive : true , force : true } ) // not very safe!
61
60
} )
62
61
} )
63
62
64
63
describe ( 'untar' , ( ) => {
65
- it ( 'should fail if source file is missing' , async ( ) => {
64
+ it ( 'should fail if source file is missing' , ( ) => {
66
65
expect . assertions ( 1 )
67
- await expect ( zippy . untar ( '' , '' ) ) . rejects . toThrow ( MissingArgumentError )
66
+ expect ( ( ) => { zippy . untar ( '' , '' ) } ) . toThrow ( MissingArgumentError )
68
67
} )
69
68
70
- it ( 'should fail if destination file is missing' , async ( ) => {
69
+ it ( 'should fail if destination file is missing' , ( ) => {
71
70
expect . assertions ( 1 )
72
- await expect ( zippy . untar ( '' , '' ) ) . rejects . toThrow ( MissingArgumentError )
71
+ expect ( ( ) => { zippy . untar ( '' , '' ) } ) . toThrow ( MissingArgumentError )
73
72
} )
74
73
75
- it ( 'should fail if source file is invalid' , async ( ) => {
74
+ it ( 'should fail if source file is invalid' , ( ) => {
76
75
expect . assertions ( 1 )
77
- await expect ( zippy . untar ( '/INVALID' , os . tmpdir ( ) ) ) . rejects . toThrow ( IllegalArgumentError )
76
+ expect ( ( ) => { zippy . untar ( '/INVALID' , os . tmpdir ( ) ) } ) . toThrow ( IllegalArgumentError )
78
77
} )
79
78
80
- it ( 'should fail for a directory' , async ( ) => {
79
+ it ( 'should fail for a directory' , ( ) => {
81
80
expect . assertions ( 1 )
82
- await expect ( zippy . untar ( 'test/data' , os . tmpdir ( ) ) ) . rejects . toThrow ( SoloError )
81
+ expect ( ( ) => { zippy . untar ( 'test/data' , os . tmpdir ( ) ) } ) . toThrow ( SoloError )
83
82
} )
84
83
85
- it ( 'should fail for a non-tar file' , async ( ) => {
84
+ it ( 'should fail for a non-tar file' , ( ) => {
86
85
expect . assertions ( 1 )
87
- await expect ( zippy . untar ( 'test/data/test.txt' , os . tmpdir ( ) ) ) . rejects . toThrow ( SoloError )
86
+ expect ( ( ) => { zippy . untar ( 'test/data/test.txt' , os . tmpdir ( ) ) } ) . toThrow ( SoloError )
88
87
} )
89
88
90
- it ( 'should succeed for valid inputs' , async ( ) => {
89
+ it ( 'should succeed for valid inputs' , ( ) => {
91
90
const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'installer-' ) )
92
91
const tarFile = `${ tmpDir } /test.tar.gz`
93
- await expect ( zippy . tar ( 'test/data/.empty' , tarFile ) ) . resolves . toBe ( tarFile )
94
- await expect ( zippy . untar ( tarFile , tmpDir , true ) ) . resolves . toBe ( tmpDir )
92
+ expect ( zippy . tar ( 'test/data/.empty' , tarFile ) , 'tar file should match' ) . toBe ( tarFile )
93
+ expect ( zippy . untar ( tarFile , tmpDir ) , 'tmp dir should match' ) . toBe ( tmpDir )
95
94
fs . rmSync ( tmpDir , { recursive : true , force : true } ) // not very safe!
96
95
} )
97
96
} )
0 commit comments