-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.test.ts
More file actions
32 lines (26 loc) · 1.23 KB
/
Copy pathexamples.test.ts
File metadata and controls
32 lines (26 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import chaiExec from '@jsdevtools/chai-exec';
import chai, { expect } from 'chai';
import { readdirSync } from 'fs';
chai.use(chaiExec);
const ENABLE_EXAMPLES_TEST = process.env['ENABLE_EXAMPLES_TEST'];
const hint = !ENABLE_EXAMPLES_TEST ? ' (enable it by setting `ENABLE_EXAMPLES_TEST`)' : '';
describe(`::examples${hint}`, function () {
const js = readdirSync('./examples')
.filter(f => f.endsWith('.mjs') || f.endsWith('.js') || f.endsWith('.ts'));
js.forEach(file => {
it(file, function () {
if (!ENABLE_EXAMPLES_TEST) this.skip();
// Increase timeout to avoid failing in CI
this.timeout(30000);
// Node's colorized output needs to be disabled for snapshot testing when running in CI
// https://nodejs.org/api/cli.html#force_color1-2-3
const env = { ...process.env, 'FORCE_COLOR': '0' };
const cli = file.endsWith('.ts')
? chaiExec('node', `dist/examples/${file.slice(0, -3)}.js`, { env })
: chaiExec(`examples/${file}`, { env });
expect(cli).stderr.to.be.empty;
expect(cli).stdout.to.matchSnapshot('out', this);
expect(cli).to.exit.with.code(0);
});
});
});