Skip to content

Commit acf3e08

Browse files
committed
more tests
1 parent aadc6da commit acf3e08

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it, mock } from 'node:test';
3+
4+
mock.module('node:fs/promises', {
5+
namedExports: {
6+
readFile: mock.fn(() => Promise.resolve('<html>{{title}}</html>')),
7+
writeFile: mock.fn(() => Promise.resolve()),
8+
},
9+
});
10+
11+
const { executeServerCode, processEntry } = await import('../index.mjs');
12+
13+
describe('executeServerCode', () => {
14+
it('should execute and return the `code` variable', async () => {
15+
const result = await executeServerCode('code = "test"', mock.fn());
16+
assert.equal(typeof result, 'string');
17+
});
18+
});
19+
20+
describe('processEntry', () => {
21+
it('should return HTML and CSS', async () => {
22+
const entry = {
23+
type: 'Literal',
24+
data: {
25+
heading: { data: { name: 'Test' } },
26+
api: 'test',
27+
},
28+
};
29+
30+
const uuid = JSON.stringify(crypto.randomUUID());
31+
32+
const result = await processEntry(
33+
entry,
34+
'{{{javascript}}}',
35+
{
36+
buildServerProgram: mock.fn(() => ''),
37+
buildClientProgram: mock.fn(() => uuid),
38+
},
39+
mock.fn(),
40+
null
41+
);
42+
43+
assert.ok(result.html.startsWith(uuid));
44+
});
45+
});

src/generators/web/build/__tests__/plugins.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { describe, it, mock } from 'node:test';
55
const existsSync = mock.fn();
66
mock.module('node:fs', { namedExports: { ...fs, existsSync } });
77

8-
const { uiComponentsResolverPlugin } = await import('../plugins.mjs');
8+
const { default: getPlugins } = await import('../plugins.mjs');
99

1010
describe('uiComponentsResolverPlugin', async () => {
1111
let onResolveCallback;
1212

13-
uiComponentsResolverPlugin.setup({
13+
getPlugins(true)[0].setup({
1414
onResolve: (_, callback) => {
1515
onResolveCallback = callback;
1616
},

src/generators/web/build/plugins.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import postcssCalc from 'postcss-calc';
1313
* strategy where it first tries to find an index.tsx file, then falls back to a
1414
* .tsx file with the same name.
1515
*/
16-
export const uiComponentsResolverPlugin = {
16+
const uiComponentsResolverPlugin = {
1717
name: 'ui-components-resolver',
1818

1919
/**

src/generators/web/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import createASTBuilder from './build/generate.mjs';
1717
* @param {ReturnType<createRequire>} require - Node.js require function for dependencies
1818
* @returns {Promise<string>} The rendered HTML output
1919
*/
20-
async function executeServerCode(serverCode, require) {
20+
export async function executeServerCode(serverCode, require) {
2121
const { js: bundledServer } = await bundleCode(serverCode, { server: true });
2222

2323
const executedFunction = new Function(
@@ -37,7 +37,7 @@ async function executeServerCode(serverCode, require) {
3737
* @param {string} output - Output directory path
3838
* @returns {Promise<{html: string, css?: string}>}
3939
*/
40-
async function processEntry(
40+
export async function processEntry(
4141
entry,
4242
template,
4343
{ buildServerProgram, buildClientProgram },

0 commit comments

Comments
 (0)