Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Aug 24, 2024
1 parent 5b8cac5 commit c634da4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/brisa/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
yellowLog,
} from './utils/log/log-color';

const IS_SERVE_PROCESS = process.argv[1].endsWith(
path.join('brisa', 'out', 'cli', 'serve', 'index.js'),
const IS_SERVE_PROCESS = Boolean(
process.argv[1]?.endsWith?.(
path.join('brisa', 'out', 'cli', 'serve', 'index.js'),
),
);
const rootDir = process.cwd();
const staticExportOutputOption = new Set([
Expand Down
16 changes: 16 additions & 0 deletions packages/brisa/src/utils/render-to-string/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, beforeEach, spyOn, afterEach } from 'bun:test';
import renderToString from '.';
import { spawnSync } from 'child_process';

let mockLog: ReturnType<typeof spyOn>;

Expand All @@ -22,6 +23,21 @@ describe('utils', () => {
expect(mockLog).not.toHaveBeenCalled();
});

it('should render to string correctly in Node.js', async () => {
const command = spawnSync('node', [
'--input-type=module',
'-e',
`
import { jsx } from '${import.meta.dirname}/../../../jsx-runtime/index.js';
import { renderToString } from '${import.meta.dirname}/../../../server/index.js';
const element = jsx('div', { children: 'Hello, World!' });
renderToString(element).then(console.log);
`,
]);
expect(command.error).toBeUndefined();
expect(command.stdout.toString()).toBe('<div>Hello, World!</div>\n');
});

it('should render the real content without suspense by default', async () => {
const Component = async () => <div>test</div>;
Component.suspense = () => <div>suspense</div>;
Expand Down

0 comments on commit c634da4

Please sign in to comment.