Skip to content

Commit

Permalink
chore(repo): add additional tests for config loading from parent dire…
Browse files Browse the repository at this point in the history
…ctories, and picking up disableDefaultStyle in render from config
  • Loading branch information
shellscape committed Nov 4, 2024
1 parent f28048c commit c6f4c2e
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 14 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`loadConfig → parent dir > loadConfig 1`] = `
{
"logLevel": "info",
"plugins": [
{
"log": LogLevel {
"currentLevel": 2,
"debug": [Function],
"error": [Function],
"info": [Function],
"log": [Function],
"methodFactory": LogFactory {
"options": {
"level": [Function],
"name": [Function],
"ready": {
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
},
"template": "[{{time}}] jsx-email ∵ root/minify {{level}} ",
"time": [Function],
},
"ready": {
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
},
Symbol(log-instance): [Circular],
Symbol(log-levels): {
"DEBUG": 1,
"ERROR": 4,
"INFO": 2,
"SILENT": 5,
"TRACE": 0,
"WARN": 3,
},
},
"name": "dot-log:∵ root/minify",
"options": {
"factory": LogFactory {
"options": {
"level": [Function],
"name": [Function],
"ready": {
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
},
"template": "[{{time}}] jsx-email ∵ root/minify {{level}} ",
"time": [Function],
},
"ready": {
"promise": Promise {},
"reject": [Function],
"resolve": [Function],
},
Symbol(log-instance): [Circular],
Symbol(log-levels): {
"DEBUG": 1,
"ERROR": 4,
"INFO": 2,
"SILENT": 5,
"TRACE": 0,
"WARN": 3,
},
},
"id": "dot-log:∵ root/minify",
"level": "info",
"name": "dot-log:∵ root/minify",
"prefix": undefined,
},
"trace": [Function],
"type": "LogLevel",
"warn": [Function],
},
"name": "root/minify",
"process": [Function],
"symbol": Symbol(jsx-email/plugin),
},
],
"render": {
"disableDefaultStyle": true,
"inlineCss": false,
"minify": true,
"plainText": false,
"pretty": false,
},
"symbol": Symbol(jsx-email/config),
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { loadConfig } from '../../../../../src/config.js';

describe('loadConfig → parent dir', async () => {
test('loadConfig', async () => {
const config = await loadConfig(__dirname);
expect(config).toBeDefined();
expect(config).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'jsx-email/config';

export const config = defineConfig({
render: { disableDefaultStyle: true, minify: true }
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`config → render > render disableDefaultStyle from config 1`] = `
"<!DOCTYPE html PUBLIC \\"-//W3C//DTD XHTML 1.0 Transitional//EN\\" \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\">
<html>
<body><a href=\\"https://bat.man\\" style></a></body>
</html>"
`;
17 changes: 17 additions & 0 deletions packages/jsx-email/test/config/render/config-render.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import { loadConfig } from '../../../src/config.js';
import { render } from '../../../src/renderer/render.js';
import { Template } from '../../render/fixtures/components.js';

// process.chdir(__dirname);

describe('config → render', async () => {
test('render disableDefaultStyle from config', async () => {
// Note: load the config from the target directory first, so it'll be picked up on cache
// vitest makes it hard to change the workding directory due to workers use
await loadConfig(__dirname);
const result = await render(<Template />);
expect(result).toMatchSnapshot();
});
});
5 changes: 5 additions & 0 deletions packages/jsx-email/test/config/render/jsx-email.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'jsx-email/config';

export const config = defineConfig({
render: { disableDefaultStyle: true, minify: false, pretty: true }
});
9 changes: 9 additions & 0 deletions packages/jsx-email/test/render/fixtures/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import { Link } from '../../../dist/esm';

export const Template: React.FC = () => (
<>
<Link href="https://bat.man" />
</>
);

0 comments on commit c6f4c2e

Please sign in to comment.