@menapo/email 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/index-CSAt1cGc.d.ts +82 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/src-nwP-sVbY.js +707 -0
- package/dist/test.d.ts +9 -0
- package/dist/test.js +34 -0
- package/dist/vite.d.ts +5 -0
- package/dist/vite.js +957 -0
- package/package.json +65 -3
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { n as Rendered } from "./index-CSAt1cGc.js";
|
|
2
|
+
//#region src/test.d.ts
|
|
3
|
+
export interface SampleRender extends Rendered {
|
|
4
|
+
/** `<export>.<sample>`: a snapshot file name. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly warnings: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function renderSamples(module: Readonly<Record<string, unknown>>): Promise<SampleRender[]>;
|
|
9
|
+
//#endregion
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { a as registry, r as isEmail, t as render } from "./src-nwP-sVbY.js";
|
|
2
|
+
//#region src/test.ts
|
|
3
|
+
/**
|
|
4
|
+
* `@menapo/email/test`: every email of a module rendered with each of its
|
|
5
|
+
* samples, for snapshot tests (PLAN §1.3). Under the plugin the dev checks
|
|
6
|
+
* run too; their warnings come back with each result. The locale is the
|
|
7
|
+
* test's: under Vitest, vi18n renders source text unless the test opens one
|
|
8
|
+
* with `createTestI18n()` from `@menapo/vi18n/test`, which `render()` follows.
|
|
9
|
+
*/
|
|
10
|
+
async function renderSamples(module) {
|
|
11
|
+
const out = [];
|
|
12
|
+
const reg = registry();
|
|
13
|
+
for (const [name, value] of Object.entries(module)) {
|
|
14
|
+
if (!isEmail(value)) continue;
|
|
15
|
+
for (const [sample, props] of Object.entries(value.samples)) {
|
|
16
|
+
const warnings = [];
|
|
17
|
+
const before = reg.warn;
|
|
18
|
+
reg.warn = (message) => warnings.push(message);
|
|
19
|
+
try {
|
|
20
|
+
const rendered = await render(value, props, { name });
|
|
21
|
+
out.push({
|
|
22
|
+
...rendered,
|
|
23
|
+
name: `${name}.${sample}`,
|
|
24
|
+
warnings
|
|
25
|
+
});
|
|
26
|
+
} finally {
|
|
27
|
+
reg.warn = before;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { renderSamples };
|