chore: test.cb gone
MODIFY
packages/ses/test/test-console-error-trap.js
packages/ses/test/test-console-error-trap.js
@@ -4,7 +4,12 @@ import { exec } from 'child_process';
const cwd = url.fileURLToPath(new URL('console-error-trap', import.meta.url));
-const exitAssertions = (t, expectedCode, altExpectedCode = expectedCode) => {
+const exitAssertions = (
+ t,
+ resolve,
+ expectedCode,
+ altExpectedCode = expectedCode,
+) => {
return (err, stdout, stderr) => {
t.log({ stdout, stderr, code: err.code, expectedCode, altExpectedCode });
// Unix error codes are uint8.
@@ -34,38 +39,49 @@ const exitAssertions = (t, expectedCode, altExpectedCode = expectedCode) => {
!stderr.includes('Error#2'),
'stderr should not contain second error message',
);
- t.end();
+ resolve(true);
};
};
-test.cb('errors reveal their stacks', t => {
+test('errors reveal their stacks', async t => {
t.plan(5);
- exec('node default.js', { cwd }, exitAssertions(t, 255));
+ await new Promise(resolve => {
+ exec('node default.js', { cwd }, exitAssertions(t, resolve, 255));
+ });
});
-test.cb('errors reveal their stacks with errorTrapping: platform', t => {
+test('errors reveal their stacks with errorTrapping: platform', async t => {
t.plan(5);
- exec('node platform.js', { cwd }, exitAssertions(t, 255));
+ await new Promise(resolve => {
+ exec('node platform.js', { cwd }, exitAssertions(t, resolve, 255));
+ });
});
-test.cb('errors reveal their stacks with errorTrapping: exit', t => {
+test('errors reveal their stacks with errorTrapping: exit', async t => {
t.plan(5);
- exec('node exit.js', { cwd }, exitAssertions(t, 255));
+ await new Promise(resolve => {
+ exec('node exit.js', { cwd }, exitAssertions(t, resolve, 255));
+ });
});
-test.cb('errors reveal their stacks with errorTrapping: exit with code', t => {
+test('errors reveal their stacks with errorTrapping: exit with code', async t => {
t.plan(5);
- exec('node exit-code.js', { cwd }, exitAssertions(t, 127));
+ await new Promise(resolve => {
+ exec('node exit-code.js', { cwd }, exitAssertions(t, resolve, 127));
+ });
});
-test.cb('errors reveal their stacks with errorTrapping: abort', t => {
+test('errors reveal their stacks with errorTrapping: abort', async t => {
t.plan(5);
// Mac exits with null, Linux exits with code 134
- exec('node abort.js', { cwd }, exitAssertions(t, null, 134));
+ await new Promise(resolve => {
+ exec('node abort.js', { cwd }, exitAssertions(t, resolve, null, 134));
+ });
});
-test.cb('errors reveal their stacks with errorTrapping: report', t => {
+test('errors reveal their stacks with errorTrapping: report', async t => {
t.plan(5);
+ await new Promise(resolve => {
exec('node report.js', { cwd }, (err, stdout, stderr) => {
t.log({ stdout, stderr });
t.is(err, null);
@@ -85,6 +101,7 @@ test.cb('errors reveal their stacks with errorTrapping: report', t => {
stderr.includes('Error#2: I am once again'),
'stderr should contain second error message',
);
- t.end();
+ resolve(true);
+ });
});
});

MODIFY
packages/ses/test/test-console-rejection-trap.js
packages/ses/test/test-console-rejection-trap.js
@@ -6,7 +6,12 @@ const cwd = url.fileURLToPath(
new URL('console-rejection-trap', import.meta.url),
);
-const exitAssertions = (t, expectedCode, altExpectedCode = expectedCode) => {
+const exitAssertions = (
+ t,
+ resolve,
+ expectedCode,
+ altExpectedCode = expectedCode,
+) => {
return (err, stdout, stderr) => {
// Unix error codes are uint8.
// Windows error codes are uint32.
@@ -46,24 +51,27 @@ const exitAssertions = (t, expectedCode, altExpectedCode = expectedCode) => {
code === 0 || !stderr.includes('Error#2'),
'failed stderr should not contain second error message',
);
- t.end();
+ resolve(true);
};
};
-test.cb('rejections reveal their stacks by default', t => {
+test('rejections reveal their stacks by default', async t => {
t.plan(6);
- exec('node default.js', { cwd }, exitAssertions(t, 0));
+ await new Promise(resolve =>
+ exec('node default.js', { cwd }, exitAssertions(t, resolve, 0)),
+ );
});
-test.cb('rejections reveal their stacks by report', t => {
+test('rejections reveal their stacks by report', async t => {
t.plan(6);
- exec('node report.js', { cwd }, exitAssertions(t, 0));
+ await new Promise(resolve =>
+ exec('node report.js', { cwd }, exitAssertions(t, resolve, 0)),
+ );
});
-test.cb(
- 'rejections are uncaught exceptions with unhandledRejectionTrapping: none',
- t => {
+test('rejections are uncaught exceptions with unhandledRejectionTrapping: none', async t => {
t.plan(4);
+ await new Promise(resolve =>
exec('node none.js', { cwd }, (err, stdout, stderr) => {
let code;
if (err && err.code === null) {
@@ -89,7 +97,7 @@ test.cb(
!stderr.includes('Error#') && !stderr.includes('Error#'),
'stderr should not contain SES errors',
);
- t.end();
- });
- },
+ resolve(true);
+ }),
);
+});

MODIFY
packages/ses/test/test-package.js
packages/ses/test/test-package.js
@@ -28,12 +28,13 @@ const table = {
const stdio = ['ignore', 'ignore', 'ignore'];
for (const [name, { args, code }] of Object.entries(table)) {
- test.cb(name, t => {
- t.plan(1);
+ test(name, async t => {
+ await new Promise(resolve => {
const child = spawn('node', args, { cwd, stdio });
child.on('close', actualCode => {
t.is(actualCode, code);
- t.end();
+ resolve(true);
+ });
});
});
}

chore: test.cb gone