1- 'use strict ';
2- const fs = require ( 'fs' ) ;
3- const path = require ( 'path' ) ;
4- const test = require ( 'ava' ) ;
5- const execa = require ( 'execa' ) ;
6- const tempy = require ( 'tempy' ) ;
7- const binCheck = require ( 'bin-check' ) ;
8- const binBuild = require ( 'bin-build' ) ;
9- const compareSize = require ( 'compare-size' ) ;
10- const cwebp = require ( '..' ) ;
1+ import fs from 'node:fs ';
2+ import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
4+ import test from 'ava' ;
5+ import execa from 'execa' ;
6+ import tempy from 'tempy' ;
7+ import binCheck from 'bin-check' ;
8+ import binBuild from 'bin-build' ;
9+ import compareSize from 'compare-size' ;
10+ import cwebp from '../index.js' ;
1111
1212test ( 'rebuild the cwebp binaries' , async t => {
1313 const temporary = tempy . directory ( ) ;
14+ const source = fileURLToPath ( new URL ( '../vendor/source/libwebp-1.1.0.tar.gz' , import . meta. url ) ) ;
1415
15- await binBuild
16- . file ( path . resolve ( __dirname , '../vendor/source/libwebp-1.1.0.tar.gz' ) , [
17- `./configure --disable-shared --prefix="${ temporary } " --bindir="${ temporary } "` ,
18- 'make && make install'
19- ] ) ;
16+ await binBuild . file ( source , [
17+ `./configure --disable-shared --prefix="${ temporary } " --bindir="${ temporary } "` ,
18+ 'make && make install' ,
19+ ] ) ;
2020
2121 t . true ( fs . existsSync ( path . join ( temporary , 'cwebp' ) ) ) ;
2222} ) ;
@@ -27,12 +27,12 @@ test('return path to binary and verify that it is working', async t => {
2727
2828test ( 'minify and convert a PNG to WebP' , async t => {
2929 const temporary = tempy . directory ( ) ;
30- const src = path . join ( __dirname , ' fixtures/test.png') ;
30+ const src = fileURLToPath ( new URL ( './ fixtures/test.png', import . meta . url ) ) ;
3131 const dest = path . join ( temporary , 'test-png.webp' ) ;
3232 const args = [
3333 src ,
3434 '-o' ,
35- dest
35+ dest ,
3636 ] ;
3737
3838 await execa ( cwebp , args ) ;
@@ -43,12 +43,12 @@ test('minify and convert a PNG to WebP', async t => {
4343
4444test ( 'minify and convert a JPG to WebP' , async t => {
4545 const temporary = tempy . directory ( ) ;
46- const src = path . join ( __dirname , ' fixtures/test.jpg') ;
46+ const src = fileURLToPath ( new URL ( './ fixtures/test.jpg', import . meta . url ) ) ;
4747 const dest = path . join ( temporary , 'test-jpg.webp' ) ;
4848 const args = [
4949 src ,
5050 '-o' ,
51- dest
51+ dest ,
5252 ] ;
5353
5454 await execa ( cwebp , args ) ;
0 commit comments