-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathexamples.test.mts
More file actions
23 lines (19 loc) · 949 Bytes
/
examples.test.mts
File metadata and controls
23 lines (19 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { beforeAll, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { readdirSync } from 'node:fs';
import { resolve } from 'node:path';
import rulesEngineDefault, * as ruleEngine from '../src/index.mjs';
const exampleDir = resolve(__dirname, '../examples');
describe('examples', () => {
beforeAll(() => {
vi.mock('json-rules-engine', () => ({...ruleEngine, default: rulesEngineDefault }));
});
beforeEach(() => {
vi.spyOn(console, 'log');
vi.spyOn(console, 'error');
})
it.each(readdirSync(exampleDir).filter(fileName => fileName.endsWith(".mts")))('example %s', async (filename) => {
await (await import(resolve(exampleDir, filename))).default;
expect.soft((console.log as Mock).mock.calls).toMatchSnapshot("expected consistent console logs");
expect.soft((console.error as Mock).mock.calls).toMatchSnapshot("expected consistent console errors");
})
})