1- import fs from 'fs' ;
2- import path from 'path' ;
1+ import process from 'node:process' ;
2+ import fs from 'node:fs' ;
3+ import path from 'node:path' ;
4+ import { promisify } from 'node:util' ;
5+ import { fileURLToPath } from 'node:url' ;
36import nock from 'nock' ;
4- import pathExists from 'path-exists' ;
5- import pify from 'pify ' ;
7+ import { pathExists } from 'path-exists' ;
8+ import executable from 'executable ' ;
69import rimraf from 'rimraf' ;
7- import test from 'ava' ;
810import tempy from 'tempy' ;
9- import executable from 'executable' ;
10- import Fn from '.' ;
11+ import test from 'ava' ;
12+ import BinWrapper from './index.js' ;
13+
14+ const __filename = fileURLToPath ( import . meta. url ) ;
15+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1116
12- const rimrafP = pify ( rimraf ) ;
17+ const rimrafP = promisify ( rimraf ) ;
1318const fixture = path . join . bind ( path , __dirname , 'fixtures' ) ;
1419
1520test . beforeEach ( ( ) => {
@@ -25,44 +30,44 @@ test.beforeEach(() => {
2530} ) ;
2631
2732test ( 'expose a constructor' , t => {
28- t . is ( typeof Fn , 'function' ) ;
33+ t . is ( typeof BinWrapper , 'function' ) ;
2934} ) ;
3035
3136test ( 'add a source' , t => {
32- const bin = new Fn ( ) . src ( 'http://foo.com/bar.tar.gz' ) ;
37+ const bin = new BinWrapper ( ) . src ( 'http://foo.com/bar.tar.gz' ) ;
3338 t . is ( bin . _src [ 0 ] . url , 'http://foo.com/bar.tar.gz' ) ;
3439} ) ;
3540
3641test ( 'add a source to a specific os' , t => {
37- const bin = new Fn ( ) . src ( 'http://foo.com' , process . platform ) ;
42+ const bin = new BinWrapper ( ) . src ( 'http://foo.com' , process . platform ) ;
3843 t . is ( bin . _src [ 0 ] . os , process . platform ) ;
3944} ) ;
4045
4146test ( 'set destination directory' , t => {
42- const bin = new Fn ( ) . dest ( path . join ( __dirname , 'foo' ) ) ;
47+ const bin = new BinWrapper ( ) . dest ( path . join ( __dirname , 'foo' ) ) ;
4348 t . is ( bin . _dest , path . join ( __dirname , 'foo' ) ) ;
4449} ) ;
4550
4651test ( 'set which file to use as the binary' , t => {
47- const bin = new Fn ( ) . use ( 'foo' ) ;
52+ const bin = new BinWrapper ( ) . use ( 'foo' ) ;
4853 t . is ( bin . _use , 'foo' ) ;
4954} ) ;
5055
5156test ( 'set a version range to test against' , t => {
52- const bin = new Fn ( ) . version ( '1.0.0' ) ;
57+ const bin = new BinWrapper ( ) . version ( '1.0.0' ) ;
5358 t . is ( bin . _version , '1.0.0' ) ;
5459} ) ;
5560
5661test ( 'get the binary path' , t => {
57- const bin = new Fn ( )
62+ const bin = new BinWrapper ( )
5863 . dest ( 'tmp' )
5964 . use ( 'foo' ) ;
6065
6166 t . is ( bin . path ( ) , path . join ( 'tmp' , 'foo' ) ) ;
6267} ) ;
6368
6469test ( 'verify that a binary is working' , async t => {
65- const bin = new Fn ( )
70+ const bin = new BinWrapper ( )
6671 . src ( 'http://foo.com/gifsicle.tar.gz' )
6772 . dest ( tempy . directory ( ) )
6873 . use ( process . platform === 'win32' ? 'gifsicle.exe' : 'gifsicle' ) ;
@@ -73,7 +78,7 @@ test('verify that a binary is working', async t => {
7378} ) ;
7479
7580test ( 'meet the desired version' , async t => {
76- const bin = new Fn ( )
81+ const bin = new BinWrapper ( )
7782 . src ( 'http://foo.com/gifsicle.tar.gz' )
7883 . dest ( tempy . directory ( ) )
7984 . use ( process . platform === 'win32' ? 'gifsicle.exe' : 'gifsicle' )
@@ -85,7 +90,7 @@ test('meet the desired version', async t => {
8590} ) ;
8691
8792test ( 'download files even if they are not used' , async t => {
88- const bin = new Fn ( { strip : 0 , skipCheck : true } )
93+ const bin = new BinWrapper ( { strip : 0 , skipCheck : true } )
8994 . src ( 'http://foo.com/gifsicle-darwin.tar.gz' )
9095 . src ( 'http://foo.com/gifsicle-win32.tar.gz' )
9196 . src ( 'http://foo.com/test.js' )
@@ -104,7 +109,7 @@ test('download files even if they are not used', async t => {
104109} ) ;
105110
106111test ( 'skip running binary check' , async t => {
107- const bin = new Fn ( { skipCheck : true } )
112+ const bin = new BinWrapper ( { skipCheck : true } )
108113 . src ( 'http://foo.com/gifsicle.tar.gz' )
109114 . dest ( tempy . directory ( ) )
110115 . use ( process . platform === 'win32' ? 'gifsicle.exe' : 'gifsicle' ) ;
@@ -115,15 +120,15 @@ test('skip running binary check', async t => {
115120} ) ;
116121
117122test ( 'error if no binary is found and no source is provided' , async t => {
118- const bin = new Fn ( )
123+ const bin = new BinWrapper ( )
119124 . dest ( tempy . directory ( ) )
120125 . use ( process . platform === 'win32' ? 'gifsicle.exe' : 'gifsicle' ) ;
121126
122- await t . throws ( bin . run ( ) , 'No binary found matching your system. It\'s probably not supported.' ) ;
127+ await t . throwsAsync ( bin . run ( ) , undefined , 'No binary found matching your system. It\'s probably not supported.' ) ;
123128} ) ;
124129
125130test ( 'downloaded files are set to be executable' , async t => {
126- const bin = new Fn ( { strip : 0 , skipCheck : true } )
131+ const bin = new BinWrapper ( { strip : 0 , skipCheck : true } )
127132 . src ( 'http://foo.com/gifsicle-darwin.tar.gz' )
128133 . src ( 'http://foo.com/gifsicle-win32.tar.gz' )
129134 . src ( 'http://foo.com/test.js' )
@@ -134,7 +139,7 @@ test('downloaded files are set to be executable', async t => {
134139
135140 const files = fs . readdirSync ( bin . dest ( ) ) ;
136141
137- files . forEach ( fileName => {
142+ for ( const fileName of files ) {
138143 t . true ( executable . sync ( path . join ( bin . dest ( ) , fileName ) ) ) ;
139- } ) ;
144+ }
140145} ) ;
0 commit comments