Skip to content

Commit 09d3a7d

Browse files
committed
feat: upgrade unassert to v2
1 parent 1f0b33a commit 09d3a7d

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

bin/cmd.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ const { createReadStream } = require('fs');
1717
const concat = require('concat-stream');
1818
const { parse } = require('acorn');
1919
const { generate } = require('escodegen');
20-
const unassert = require('unassert');
20+
const { unassertAst, defaultOptions } = require('unassert');
21+
22+
// add `power-assert` to target modules to avoid breaking change
23+
function generateUnassertOptions () {
24+
const opts = defaultOptions();
25+
opts.modules.push('power-assert');
26+
return opts;
27+
}
2128

2229
function transform (code) {
2330
const ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
24-
return generate(unassert(ast));
31+
return generate(unassertAst(ast, generateUnassertOptions()));
2532
}
2633

2734
const args = process.argv.slice(2);

test/fixtures/func/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict';
2-
function add(a, b) {
2+
async function add(a, b) {
33
return a + b;
44
}

test/fixtures/func/fixture.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
function add (a, b) {
3+
const assert = require('node:assert/strict');
4+
5+
async function add (a, b) {
46
console.assert(typeof a === 'number');
57

68
assert(!isNaN(a));
@@ -52,5 +54,9 @@ function add (a, b) {
5254

5355
assert.ifError(a);
5456
assert.fail(a, b, 'assertion message', '==');
57+
58+
await assert.rejects(Promise.reject(new Error(`error: ${a}`)));
59+
await assert.doesNotReject(Promise.resolve(b));
60+
5561
return a + b;
5662
}

test/fixtures/not_an_expression_statement/expected.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/fixtures/not_an_expression_statement/fixture.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ describe('unassert-cli', () => {
4545
testUnassertCommand('assignment_singlevar');
4646
testUnassertCommand('es6module');
4747
testUnassertCommand('es6module_powerassert');
48-
testUnassertCommand('not_an_expression_statement');
4948
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy