Skip to content

Commit c69f409

Browse files
author
Leon Si
committed
test: more test rewrites
1 parent b182efa commit c69f409

File tree

1 file changed

+71
-69
lines changed

1 file changed

+71
-69
lines changed

test/suites/ets.test.ts

+71-69
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ describe('<%%', () => {
400400
expect(await ets.render('<%%- "foo" %>')).toEqual('<%- "foo" %>');
401401
});
402402

403-
test('work without an end tag', () => {
403+
test('work without an end tag', async () => {
404404
expect(ets.render('<%%')).toEqual('<%');
405405
expect(
406406
await ets.render({
@@ -412,98 +412,102 @@ describe('<%%', () => {
412412
});
413413
});
414414

415-
suite('%%>', () => {
416-
test('produce literal', () => {
417-
assert.equal(ets.render('%%>'), '%>');
418-
assert.equal(ets.render(' >', {}, { delimiter: ' ' }), ' >');
415+
describe('%%>', () => {
416+
test('produce literal', async () => {
417+
expect(await ets.render('%%>')).toEqual('%>');
418+
expect(
419+
await ets.render({ template: ' >', options: { delimiter: ' ' } })
420+
).toEqual(' >');
419421
});
420422
});
421423

422-
suite('<%_ and _%>', () => {
423-
test('slurps spaces and tabs', () => {
424-
assert.equal(
425-
ets.render(fixture('space-and-tab-slurp.ets'), { users }),
426-
fixture('space-and-tab-slurp.html')
427-
);
424+
describe('<%_ and _%>', () => {
425+
test('slurps spaces and tabs', async () => {
426+
expect(
427+
await ets.render({
428+
template: fixture('space-and-tab-slurp.ets'),
429+
data: { users },
430+
})
431+
).toEqual(fixture('space-and-tab-slurp.html'));
428432
});
429433
});
430434

431-
suite('single quotes', () => {
432-
test('not mess up the constructed function', () => {
433-
assert.equal(
434-
ets.render(fixture('single-quote.ets')),
435+
describe('single quotes', () => {
436+
test('not mess up the constructed function', async () => {
437+
expect(await ets.render(fixture('single-quote.ets'))).toEqual(
435438
fixture('single-quote.html')
436439
);
437440
});
438441
});
439442

440-
suite('double quotes', () => {
441-
test('not mess up the constructed function', () => {
442-
assert.equal(
443-
ets.render(fixture('double-quote.ets')),
443+
describe('double quotes', () => {
444+
test('not mess up the constructed function', async () => {
445+
expect(await ets.render(fixture('double-quote.ets'))).toEqual(
444446
fixture('double-quote.html')
445447
);
446448
});
447449
});
448450

449-
suite('backslashes', () => {
450-
test('escape', () => {
451-
assert.equal(
452-
ets.render(fixture('backslash.ets')),
451+
describe('backslashes', () => {
452+
test('escape', async () => {
453+
expect(await ets.render(fixture('backslash.ets'))).toEqual(
453454
fixture('backslash.html')
454455
);
455456
});
456457
});
457458

458-
suite('messed up whitespace', () => {
459-
test('work', () => {
460-
assert.equal(
461-
ets.render(fixture('messed.ets'), { users }),
462-
fixture('messed.html')
463-
);
459+
describe('messed up whitespace', () => {
460+
test('work', async () => {
461+
expect(
462+
await ets.render({ template: fixture('messed.ets'), data: { users } })
463+
).toEqual(fixture('messed.html'));
464464
});
465465
});
466466

467-
suite('exceptions', () => {
468-
test('produce useful stack traces', () => {
467+
describe('exceptions', () => {
468+
test('produce useful stack traces', async () => {
469469
try {
470-
ets.render(fixture('error.ets'), {}, { filename: 'error.ets' });
471-
} catch (error) {
472-
assert.equal(error.path, 'error.ets');
473-
let errstck = error.stack.split('\n').slice(0, 8).join('\n');
474-
errstck = errstck.replace(/\n/g, lf);
475-
errstck = errstck.replace(/\r\r\n/g, lf);
476-
assert.equal(errstck, fixture('error.out'));
470+
await ets.render({
471+
template: fixture('error.ets'),
472+
options: { filename: 'error.ets' },
473+
});
474+
} catch (error: unknown) {
475+
const err = error as { path: string; stack: string };
476+
expect(err.path).toEqual('error.ets');
477+
let errorStack = err.stack.split('\n').slice(0, 8).join('\n');
478+
errorStack = errorStack.replace(/\n/g, '\n');
479+
errorStack = errorStack.replace(/\r\r\n/g, '\n');
480+
expect(errorStack).toEqual(fixture('error.out'));
477481
return;
478482
}
479483

480484
throw new Error('no error reported when there should be');
481485
});
482486

483-
test('not include fancy stack info if compileDebug is false', () => {
487+
test('not include fancy stack info if compileDebug is false', async () => {
484488
try {
485-
ets.render(
486-
fixture('error.ets'),
487-
{},
488-
{
489+
await ets.render({
490+
template: fixture('error.ets'),
491+
options: {
489492
filename: 'error.ets',
490493
compileDebug: false,
491-
}
492-
);
493-
} catch (error) {
494-
assert.ok(!error.path);
495-
let errstck = error.stack.split('\n').slice(0, 8).join('\n');
496-
errstck = errstck.replace(/\n/g, lf);
497-
errstck = errstck.replace(/\r\r\n/g, lf);
498-
assert.notEqual(errstck, fixture('error.out'));
494+
},
495+
});
496+
} catch (error: unknown) {
497+
const err = error as { path: string; stack: string };
498+
expect(!err.path).toBe(true);
499+
let errorStack = err.stack.split('\n').slice(0, 8).join('\n');
500+
errorStack = errorStack.replace(/\n/g, '\n');
501+
errorStack = errorStack.replace(/\r\r\n/g, '\n');
502+
expect(errorStack).toEqual(fixture('error.out'));
499503
return;
500504
}
501505

502506
throw new Error('no error reported when there should be');
503507
});
504508

505509
let unhook = null;
506-
test('log JS source when debug is set', (done) => {
510+
test('log JS source when debug is set', async () => {
507511
let out = '';
508512
let needToExit = false;
509513
unhook = hook_stdio(process.stdout, (str) => {
@@ -522,29 +526,27 @@ suite('exceptions', () => {
522526
ets.render(fixture('hello-world.ets'), {}, { debug: true });
523527
});
524528

525-
test('escape filename in errors', () => {
526-
assert.throws(() => {
527-
ets.render(
528-
'<% throw new Error("whoops"); %>',
529-
{},
530-
{ filename: '<script>' }
531-
);
532-
}, /Error: &lt;script&gt;/);
529+
test('escape filename in errors', async () => {
530+
await expect(async () => {
531+
await ets.render({
532+
template: '<% throw new Error("whoops"); %>',
533+
options: { filename: '<script>' },
534+
});
535+
}).rejects.toThrow(/Error: &lt;script&gt;/);
533536
});
534537

535-
test('filename in errors uses custom escape', () => {
536-
assert.throws(() => {
537-
ets.render(
538-
'<% throw new Error("whoops"); %>',
539-
{},
540-
{
538+
test('filename in errors uses custom escape', async () => {
539+
await expect(async () => {
540+
await ets.render({
541+
template: '<% throw new Error("whoops"); %>',
542+
options: {
541543
filename: '<script>',
542544
escape() {
543545
return 'zooby';
544546
},
545-
}
546-
);
547-
}, /Error: zooby/);
547+
},
548+
});
549+
}).rejects.toThrow(/Error: zooby/);
548550
});
549551

550552
teardown(() => {

0 commit comments

Comments
 (0)