Skip to content

Commit c43c858

Browse files
committed
test(jsx-email): stabilize config snapshots
1 parent 5ab4944 commit c43c858

File tree

5 files changed

+150
-6
lines changed

5 files changed

+150
-6
lines changed

packages/jsx-email/test/config/define-config.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1-
import { defineConfig } from '../../src/config.js';
2-
import { pluginSymbol } from '../../src/plugins.js';
1+
import { createRequire } from 'node:module';
2+
import { dirname } from 'node:path';
3+
4+
import loglevelnext from 'loglevelnext';
5+
6+
const require = createRequire(import.meta.url);
37

48
describe('defineConfig', async () => {
9+
beforeEach(() => {
10+
vi.restoreAllMocks();
11+
vi.resetModules();
12+
13+
process.env.FORCE_COLOR = '1';
14+
15+
const dotLogPath = require.resolve('@dot/log');
16+
const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] });
17+
18+
delete require.cache[dotLogPath];
19+
delete require.cache[chalkPath];
20+
require(chalkPath).level = 1;
21+
22+
delete (globalThis as any)[Symbol.for('jsx-email/global/config')];
23+
delete process.env.DOT_LOG_LEVEL;
24+
25+
for (const key of Object.keys(loglevelnext.loggers)) {
26+
if (key === 'default') continue;
27+
delete loglevelnext.loggers[key];
28+
}
29+
});
30+
531
test('defaults', async () => {
32+
const { defineConfig } = await import('../../src/config.js');
633
expect(await defineConfig({})).toMatchSnapshot();
734
});
835

936
test('basic set', async () => {
37+
const { defineConfig } = await import('../../src/config.js');
1038
const config = await defineConfig({
1139
render: {
1240
minify: true
@@ -16,6 +44,7 @@ describe('defineConfig', async () => {
1644
});
1745

1846
test('minify and pretty', async () => {
47+
const { defineConfig } = await import('../../src/config.js');
1948
const config = await defineConfig({
2049
render: {
2150
minify: true,
@@ -26,6 +55,7 @@ describe('defineConfig', async () => {
2655
});
2756

2857
test('plain', async () => {
58+
const { defineConfig } = await import('../../src/config.js');
2959
const config = await defineConfig({
3060
render: {
3161
minify: true,
@@ -37,6 +67,8 @@ describe('defineConfig', async () => {
3767
});
3868

3969
test('de-dupe plugins', async () => {
70+
const { defineConfig } = await import('../../src/config.js');
71+
const { pluginSymbol } = await import('../../src/plugins.js');
4072
const plugin = { name: 'batman', symbol: pluginSymbol };
4173
const config = await defineConfig({
4274
plugins: [plugin as any, plugin]

packages/jsx-email/test/config/load/dotdir/load-dotdir.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
import { loadConfig } from '../../../../src/config.js';
1+
import { createRequire } from 'node:module';
2+
import { dirname } from 'node:path';
3+
4+
import loglevelnext from 'loglevelnext';
5+
6+
const require = createRequire(import.meta.url);
27

38
describe('loadConfig → dotdir', async () => {
9+
beforeEach(() => {
10+
vi.restoreAllMocks();
11+
vi.resetModules();
12+
13+
process.env.FORCE_COLOR = '1';
14+
15+
const dotLogPath = require.resolve('@dot/log');
16+
const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] });
17+
18+
delete require.cache[dotLogPath];
19+
delete require.cache[chalkPath];
20+
require(chalkPath).level = 1;
21+
22+
delete (globalThis as any)[Symbol.for('jsx-email/global/config')];
23+
delete process.env.DOT_LOG_LEVEL;
24+
25+
for (const key of Object.keys(loglevelnext.loggers)) {
26+
if (key === 'default') continue;
27+
delete loglevelnext.loggers[key];
28+
}
29+
});
30+
431
test('loadConfig', async () => {
32+
const { loadConfig } = await import('../../../../src/config.js');
533
const config = await loadConfig(__dirname);
634
expect(config).toMatchSnapshot();
735
});

packages/jsx-email/test/config/load/mjs-json/load-mjs-json.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
import { loadConfig } from '../../../../src/config.js';
1+
import { createRequire } from 'node:module';
2+
import { dirname } from 'node:path';
3+
4+
import loglevelnext from 'loglevelnext';
5+
6+
const require = createRequire(import.meta.url);
27

38
describe('loadConfig → mjs-json', async () => {
9+
beforeEach(() => {
10+
vi.restoreAllMocks();
11+
vi.resetModules();
12+
13+
process.env.FORCE_COLOR = '1';
14+
15+
const dotLogPath = require.resolve('@dot/log');
16+
const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] });
17+
18+
delete require.cache[dotLogPath];
19+
delete require.cache[chalkPath];
20+
require(chalkPath).level = 1;
21+
22+
delete (globalThis as any)[Symbol.for('jsx-email/global/config')];
23+
delete process.env.DOT_LOG_LEVEL;
24+
25+
for (const key of Object.keys(loglevelnext.loggers)) {
26+
if (key === 'default') continue;
27+
delete loglevelnext.loggers[key];
28+
}
29+
});
30+
431
test('loadConfig', async () => {
32+
const { loadConfig } = await import('../../../../src/config.js');
533
const config = await loadConfig(__dirname);
634
expect(config).toMatchSnapshot();
735
});

packages/jsx-email/test/config/load/mjs/load-mjs.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
import { loadConfig } from '../../../../src/config.js';
1+
import { createRequire } from 'node:module';
2+
import { dirname } from 'node:path';
3+
4+
import loglevelnext from 'loglevelnext';
5+
6+
const require = createRequire(import.meta.url);
27

38
describe('loadConfig → mjs', async () => {
9+
beforeEach(() => {
10+
vi.restoreAllMocks();
11+
vi.resetModules();
12+
13+
process.env.FORCE_COLOR = '1';
14+
15+
const dotLogPath = require.resolve('@dot/log');
16+
const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] });
17+
18+
delete require.cache[dotLogPath];
19+
delete require.cache[chalkPath];
20+
require(chalkPath).level = 1;
21+
22+
delete (globalThis as any)[Symbol.for('jsx-email/global/config')];
23+
delete process.env.DOT_LOG_LEVEL;
24+
25+
for (const key of Object.keys(loglevelnext.loggers)) {
26+
if (key === 'default') continue;
27+
delete loglevelnext.loggers[key];
28+
}
29+
});
30+
431
test('loadConfig', async () => {
32+
const { loadConfig } = await import('../../../../src/config.js');
533
const config = await loadConfig(__dirname);
634
expect(config).toMatchSnapshot();
735
});

packages/jsx-email/test/config/load/parent-dir/child-dir/parent-dir.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1-
import { loadConfig } from '../../../../../src/config.js';
1+
import { createRequire } from 'node:module';
2+
import { dirname } from 'node:path';
3+
4+
import loglevelnext from 'loglevelnext';
5+
6+
const require = createRequire(import.meta.url);
27

38
describe('loadConfig → parent dir', async () => {
9+
beforeEach(() => {
10+
vi.restoreAllMocks();
11+
vi.resetModules();
12+
13+
process.env.FORCE_COLOR = '1';
14+
15+
const dotLogPath = require.resolve('@dot/log');
16+
const chalkPath = require.resolve('chalk', { paths: [dirname(dotLogPath)] });
17+
18+
delete require.cache[dotLogPath];
19+
delete require.cache[chalkPath];
20+
require(chalkPath).level = 1;
21+
22+
delete (globalThis as any)[Symbol.for('jsx-email/global/config')];
23+
delete process.env.DOT_LOG_LEVEL;
24+
25+
for (const key of Object.keys(loglevelnext.loggers)) {
26+
if (key === 'default') continue;
27+
delete loglevelnext.loggers[key];
28+
}
29+
});
30+
431
test('loadConfig', async () => {
32+
const { loadConfig } = await import('../../../../../src/config.js');
533
const config = await loadConfig(__dirname);
634
expect(config).toBeDefined();
735
expect(config).toMatchSnapshot();

0 commit comments

Comments
 (0)