Skip to content

Commit f538af8

Browse files
authored
Merge pull request #3080 from modernweb-dev/migrate/rollup-plugin-copy-node-test
refactor(rollup-plugin-copy): migrate tests to node:test
2 parents 8b2cafe + 936499f commit f538af8

4 files changed

Lines changed: 47 additions & 37 deletions

File tree

packages/rollup-plugin-copy/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"node": ">=22.0.0"
3030
},
3131
"scripts": {
32-
"test:node": "mocha test/**/*.test.js --reporter dot",
33-
"test:watch": "mocha test/**/*.test.js --watch --watch-files src,test --reporter dot"
32+
"test:node": "node --test --test-force-exit test/**/*.test.js",
33+
"test:watch": "node --test --test-force-exit --watch test/**/*.test.js"
3434
},
3535
"files": [
3636
"*.d.ts",
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
const { describe, it } = require('node:test');
2+
const assert = require('node:assert/strict');
13
const path = require('path');
2-
const { expect } = require('chai');
34
const rollup = require('rollup');
45

56
const { copy } = require('../src/copy.js');
@@ -12,12 +13,13 @@ describe('rollup-plugin-copy', () => {
1213
});
1314
const { output } = await bundle.generate({ format: 'es' });
1415

15-
expect(output.length).to.equal(5);
16-
expect(output.map(x => x.fileName).filter(x => x.endsWith('.svg'))).to.have.members([
17-
'a.svg',
18-
'b.svg',
19-
`sub${path.sep}sub-a.svg`,
20-
`sub${path.sep}sub-b.mark.svg`,
21-
]);
16+
assert.equal(output.length, 5);
17+
assert.deepEqual(
18+
output
19+
.map(x => x.fileName)
20+
.filter(x => x.endsWith('.svg'))
21+
.sort(),
22+
['a.svg', 'b.svg', `sub${path.sep}sub-a.svg`, `sub${path.sep}sub-b.mark.svg`].sort(),
23+
);
2224
});
2325
});
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1+
const { describe, it } = require('node:test');
2+
const assert = require('node:assert/strict');
13
const path = require('path');
2-
const { expect } = require('chai');
34

45
const { listFiles } = require('../src/listFiles.js');
56

67
describe('listFiles', () => {
78
it('gives a list of files', async () => {
89
const files = await listFiles('*.svg', path.resolve(__dirname, './fixture/'));
9-
expect(files.length).to.equal(2);
10-
expect(files).to.have.members([
11-
path.join(__dirname, './fixture/a.svg'),
12-
path.join(__dirname, './fixture/b.svg'),
13-
]);
10+
assert.equal(files.length, 2);
11+
assert.deepEqual(
12+
files.sort(),
13+
[path.join(__dirname, './fixture/a.svg'), path.join(__dirname, './fixture/b.svg')].sort(),
14+
);
1415
});
1516

1617
it('only gives files and no folders', async () => {
1718
const files = await listFiles('**/*.svg', path.resolve(__dirname, './fixture/'));
18-
expect(files.length).to.equal(4);
19-
expect(files).to.have.members([
20-
path.join(__dirname, './fixture/a.svg'),
21-
path.join(__dirname, './fixture/b.svg'),
22-
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
23-
path.join(__dirname, './fixture/sub/sub-a.svg'),
24-
]);
19+
assert.equal(files.length, 4);
20+
assert.deepEqual(
21+
files.sort(),
22+
[
23+
path.join(__dirname, './fixture/a.svg'),
24+
path.join(__dirname, './fixture/b.svg'),
25+
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
26+
path.join(__dirname, './fixture/sub/sub-a.svg'),
27+
].sort(),
28+
);
2529
});
2630

2731
it('will copy files inside dot folders', async () => {
2832
const files = await listFiles('**/*.svg', path.resolve(__dirname, './fixtureDot/'));
29-
expect(files.length).to.equal(1);
30-
expect(files[0]).to.match(/fixtureDot(\/|\\)\.folder(\/|\\)inside-dot-folder\.svg$/);
33+
assert.equal(files.length, 1);
34+
assert.match(files[0], /fixtureDot(\/|\\)\.folder(\/|\\)inside-dot-folder\.svg$/);
3135
});
3236
});
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1+
const { describe, it } = require('node:test');
2+
const assert = require('node:assert/strict');
13
const path = require('path');
2-
const { expect } = require('chai');
34

45
const { patternsToFiles } = require('../src/patternsToFiles.js');
56

67
describe('patternsToFiles', () => {
78
it('works with a string', async () => {
89
const files = await patternsToFiles('*.svg', path.resolve(__dirname, './fixture/'));
9-
expect(files.length).to.equal(2);
10-
expect(files).to.have.members([
11-
path.join(__dirname, './fixture/a.svg'),
12-
path.join(__dirname, './fixture/b.svg'),
13-
]);
10+
assert.equal(files.length, 2);
11+
assert.deepEqual(
12+
files.sort(),
13+
[path.join(__dirname, './fixture/a.svg'), path.join(__dirname, './fixture/b.svg')].sort(),
14+
);
1415
});
1516

1617
it('works with an array of strings ', async () => {
1718
const files = await patternsToFiles(
1819
['*.svg', 'sub/*.mark.svg'],
1920
path.resolve(__dirname, './fixture/'),
2021
);
21-
expect(files.length).to.equal(3);
22-
expect(files).to.have.members([
23-
path.join(__dirname, './fixture/a.svg'),
24-
path.join(__dirname, './fixture/b.svg'),
25-
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
26-
]);
22+
assert.equal(files.length, 3);
23+
assert.deepEqual(
24+
files.sort(),
25+
[
26+
path.join(__dirname, './fixture/a.svg'),
27+
path.join(__dirname, './fixture/b.svg'),
28+
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
29+
].sort(),
30+
);
2731
});
2832
});

0 commit comments

Comments
 (0)