From ff7fce333dac3a19367bb4c4f1f9ad90b8a39406 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 1 Sep 2023 01:06:03 +0200 Subject: [PATCH] tests: new structure --- .../{+page.server.js => +page.server.ts} | 0 package-lock.json | 1 + packages/process/package.json | 1 + packages/process/tests/processor.test.mjs | 350 ++---------------- .../default config merge/compiled.txt | 1 + .../processor/default config merge/config.mjs | 5 + .../default config merge/source.markdoc | 1 + .../processor/default config/compiled.txt | 1 + .../tests/processor/default config/config.mjs | 3 + .../processor/default config/source.markdoc | 1 + .../processor/frontmatter export/compiled.txt | 1 + .../processor/frontmatter export/config.mjs | 3 + .../frontmatter export/source.markdoc | 5 + .../processor/layout - default/compiled.txt | 1 + .../processor/layout - default/config.mjs | 9 + .../processor/layout - default/source.markdoc | 1 + .../processor/layout - named/compiled.txt | 1 + .../tests/processor/layout - named/config.mjs | 9 + .../processor/layout - named/source.markdoc | 5 + .../nodes, tags and partials/compiled.txt | 1 + .../nodes, tags and partials/config.mjs | 8 + .../nodes, tags and partials/source.markdoc | 21 ++ .../tests/processor/nodes/compiled.txt | 1 + .../process/tests/processor/nodes/config.mjs | 6 + .../tests/processor/nodes/source.markdoc | 7 + .../tests/processor/partials/compiled.txt | 1 + .../tests/processor/partials/config.mjs | 6 + .../tests/processor/partials/source.markdoc | 7 + .../process/tests/processor/tags/compiled.txt | 1 + .../process/tests/processor/tags/config.mjs | 6 + .../tests/processor/tags/source.markdoc | 5 + packages/process/tests/utils.mjs | 7 + 32 files changed, 151 insertions(+), 325 deletions(-) rename apps/demo/src/routes/playground/{+page.server.js => +page.server.ts} (100%) create mode 100644 packages/process/tests/processor/default config merge/compiled.txt create mode 100644 packages/process/tests/processor/default config merge/config.mjs create mode 100644 packages/process/tests/processor/default config merge/source.markdoc create mode 100644 packages/process/tests/processor/default config/compiled.txt create mode 100644 packages/process/tests/processor/default config/config.mjs create mode 100644 packages/process/tests/processor/default config/source.markdoc create mode 100644 packages/process/tests/processor/frontmatter export/compiled.txt create mode 100644 packages/process/tests/processor/frontmatter export/config.mjs create mode 100644 packages/process/tests/processor/frontmatter export/source.markdoc create mode 100644 packages/process/tests/processor/layout - default/compiled.txt create mode 100644 packages/process/tests/processor/layout - default/config.mjs create mode 100644 packages/process/tests/processor/layout - default/source.markdoc create mode 100644 packages/process/tests/processor/layout - named/compiled.txt create mode 100644 packages/process/tests/processor/layout - named/config.mjs create mode 100644 packages/process/tests/processor/layout - named/source.markdoc create mode 100644 packages/process/tests/processor/nodes, tags and partials/compiled.txt create mode 100644 packages/process/tests/processor/nodes, tags and partials/config.mjs create mode 100644 packages/process/tests/processor/nodes, tags and partials/source.markdoc create mode 100644 packages/process/tests/processor/nodes/compiled.txt create mode 100644 packages/process/tests/processor/nodes/config.mjs create mode 100644 packages/process/tests/processor/nodes/source.markdoc create mode 100644 packages/process/tests/processor/partials/compiled.txt create mode 100644 packages/process/tests/processor/partials/config.mjs create mode 100644 packages/process/tests/processor/partials/source.markdoc create mode 100644 packages/process/tests/processor/tags/compiled.txt create mode 100644 packages/process/tests/processor/tags/config.mjs create mode 100644 packages/process/tests/processor/tags/source.markdoc diff --git a/apps/demo/src/routes/playground/+page.server.js b/apps/demo/src/routes/playground/+page.server.ts similarity index 100% rename from apps/demo/src/routes/playground/+page.server.js rename to apps/demo/src/routes/playground/+page.server.ts diff --git a/package-lock.json b/package-lock.json index 930e016..31ece04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5828,6 +5828,7 @@ "@types/html-escaper": "^3.0.0", "@types/js-yaml": "^4.0.5", "@types/node": "^20.4.5", + "fast-glob": "^3.3.1", "prettier": "*", "publint": "^0.1.16" } diff --git a/packages/process/package.json b/packages/process/package.json index 9450921..589293b 100644 --- a/packages/process/package.json +++ b/packages/process/package.json @@ -39,6 +39,7 @@ "@types/html-escaper": "^3.0.0", "@types/js-yaml": "^4.0.5", "@types/node": "^20.4.5", + "fast-glob": "^3.3.1", "prettier": "*", "publint": "^0.1.16" } diff --git a/packages/process/tests/processor.test.mjs b/packages/process/tests/processor.test.mjs index 827776b..3b2a22c 100644 --- a/packages/process/tests/processor.test.mjs +++ b/packages/process/tests/processor.test.mjs @@ -1,7 +1,10 @@ -import { test } from 'node:test'; +import fg from 'fast-glob'; import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { basename, dirname, join } from 'node:path'; import { markdoc } from '../dist/module.js'; -import { absoulute } from './utils.mjs'; +import { absoulute, read_file } from './utils.mjs'; +import { fileURLToPath } from 'node:url'; test('preprocessor', async (context) => { const preprocess = markdoc(); @@ -10,20 +13,6 @@ test('preprocessor', async (context) => { assert.ok(preprocess.name === 'markdoc'); assert.ok('markup' in preprocess); }); - await context.test('respects default config', async () => { - const preprocess = markdoc({ - generateSchema: false, - }); - assert.deepEqual( - await preprocess.markup({ - content: '# Hello World', - filename: 'test.markdoc', - }), - { - code: '

Hello World

', - }, - ); - }); await context.test('ignores non-extension files', async () => { assert.equal( await preprocess.markup({ @@ -70,315 +59,26 @@ test('preprocessor', async (context) => { }, ); }); - await context.test('exports frontmatter', async () => { - const preprocess = markdoc(); - const content = `---\nlorem: ipsum\n---\n# Hello World`; - assert.deepEqual( - await preprocess.markup({ - content, - filename: 'test.markdoc', - }), - { - code: '

Hello World

', - }, - ); - }); - await context.test('uses tags', async () => { - const module_path = absoulute(import.meta.url, './tags/module.svelte'); - const script = ``; - const preprocess = markdoc({ - tags: module_path, - }); - assert.deepEqual( - await preprocess.markup({ - content: '{% hello %}', - filename: 'test.markdoc', - }), - { - code: `${script}
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% slot %}slot content{% /slot %}`, - filename: 'test.markdoc', - }), - { - code: `${script}

slot content

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: '{% unknown %}', - filename: 'test.markdoc', - }), - { - code: `${script}
`, - }, - ); - }); - await context.test('uses nodes', async () => { - const module_path = absoulute(import.meta.url, './nodes/module.svelte'); - const script = ``; - const preprocess = markdoc({ - nodes: module_path, - }); - assert.deepEqual( - await preprocess.markup({ - content: '# Hello World', - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `## Hello World`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `# Hello World{% #my-id %}`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `# Hello World{% .my-class %}`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - }); - await context.test('uses nodes and tags', async () => { - const nodes_module_path = absoulute( - import.meta.url, - './nodes/module.svelte', - ); - const tags_module_path = absoulute( - import.meta.url, - './tags/module.svelte', - ); - const script = ``; - const preprocess = markdoc({ - nodes: nodes_module_path, - tags: tags_module_path, - }); - assert.deepEqual( - await preprocess.markup({ - content: '# Hello World', - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `## Hello World`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `# Hello World{% #my-id %}`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `# Hello World{% .my-class %}`, - filename: 'test.markdoc', - }), - { - code: `${script}
Hello World
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: '{% hello %}', - filename: 'test.markdoc', - }), - { - code: `${script}
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% slot %}slot content{% /slot %}`, - filename: 'test.markdoc', - }), - { - code: `${script}

slot content

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: '{% unknown %}', - filename: 'test.markdoc', - }), - { - code: `${script}
`, - }, - ); - }); - await context.test('uses partials', async () => { - const partials_module_path = absoulute(import.meta.url, './partials'); - const preprocess = markdoc({ - partials: partials_module_path, - }); - assert.deepEqual( - await preprocess.markup({ - content: '{% partial file="test.md" /%}', - filename: 'test.markdoc', - }), - { - code: `

I am a partial

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="variables.md" variables={lorem: "Lorem", ipsum: "Ipsum"} /%}`, - filename: 'test.markdoc', - }), - { - code: `

Lorem Ipsum

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="nested/file.md" /%}`, - filename: 'test.markdoc', - }), - { - code: `

I am nested

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="unknown.md" /%}`, - filename: 'test.markdoc', - }), - { - code: `
`, - }, - ); - }); - await context.test('uses partials with nodes and tags', async () => { - const partials_module_path = absoulute(import.meta.url, './partials'); - const nodes_module_path = absoulute( - import.meta.url, - './nodes/module.svelte', - ); - const tags_module_path = absoulute( - import.meta.url, - './tags/module.svelte', - ); - const script = ``; - const preprocess = markdoc({ - partials: partials_module_path, - nodes: nodes_module_path, - tags: tags_module_path, - }); - assert.deepEqual( - await preprocess.markup({ - content: '{% partial file="test.md" /%}', - filename: 'test.markdoc', - }), - { - code: `${script}
I am a partial
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="variables.md" variables={lorem: "Lorem", ipsum: "Ipsum"} /%}`, - filename: 'test.markdoc', - }), - { - code: `${script}
Lorem Ipsum
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="tags.md" /%}`, - filename: 'test.markdoc', - }), - { - code: `${script}

slot content

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="nested/file.md" /%}`, - filename: 'test.markdoc', - }), - { - code: `${script}
I am nested
`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `{% partial file="unknown.md" /%}`, - filename: 'test.markdoc', - }), - { - code: `${script}
`, - }, - ); - }); - await context.test('uses layout', async () => { - const layout_default = absoulute( - import.meta.url, - './layouts/default.svelte', - ); - const layout_named = absoulute( - import.meta.url, - './layouts/named.svelte', - ); - const preprocess = markdoc({ - extensions: ['.markdoc'], - layouts: { - default: layout_default, - named: layout_named, - }, - }); - assert.deepEqual( - await preprocess.markup({ - content: '# Hello World', - filename: 'test.markdoc', - }), - { - code: `

Hello World

`, - }, - ); - assert.deepEqual( - await preprocess.markup({ - content: `--- -layout: named ---- -# Hello World`, - filename: 'test.markdoc', - }), - { - code: `

Hello World

`, - }, - ); + const stream = fg.globStream(absoulute(import.meta.url, './processor/**'), { + onlyDirectories: true, }); + const current_dir = dirname(fileURLToPath(import.meta.url)); + for await (const entry of stream) { + await context.test('tests ' + basename(entry), async () => { + const before = await read_file(join(entry, 'source.markdoc')); + const after = await read_file(join(entry, 'compiled.txt')); + const preprocess = await import(join(entry, 'config.mjs')).then( + (m) => m.default, + ); + const markup = await preprocess.markup({ + content: before, + filename: 'test.markdoc', + }); + assert.equal( + markup.code, + after.replaceAll('__PATH__', current_dir), + ); + }); + } }); diff --git a/packages/process/tests/processor/default config merge/compiled.txt b/packages/process/tests/processor/default config merge/compiled.txt new file mode 100644 index 0000000..0738991 --- /dev/null +++ b/packages/process/tests/processor/default config merge/compiled.txt @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/packages/process/tests/processor/default config merge/config.mjs b/packages/process/tests/processor/default config merge/config.mjs new file mode 100644 index 0000000..86c62eb --- /dev/null +++ b/packages/process/tests/processor/default config merge/config.mjs @@ -0,0 +1,5 @@ +import { markdoc } from '../../../dist/module.js'; + +export default markdoc({ + generateSchema: false, +}); diff --git a/packages/process/tests/processor/default config merge/source.markdoc b/packages/process/tests/processor/default config merge/source.markdoc new file mode 100644 index 0000000..e9168db --- /dev/null +++ b/packages/process/tests/processor/default config merge/source.markdoc @@ -0,0 +1 @@ +# Hello World \ No newline at end of file diff --git a/packages/process/tests/processor/default config/compiled.txt b/packages/process/tests/processor/default config/compiled.txt new file mode 100644 index 0000000..0738991 --- /dev/null +++ b/packages/process/tests/processor/default config/compiled.txt @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/packages/process/tests/processor/default config/config.mjs b/packages/process/tests/processor/default config/config.mjs new file mode 100644 index 0000000..fc0d6f3 --- /dev/null +++ b/packages/process/tests/processor/default config/config.mjs @@ -0,0 +1,3 @@ +import { markdoc } from '../../../dist/module.js'; + +export default markdoc(); diff --git a/packages/process/tests/processor/default config/source.markdoc b/packages/process/tests/processor/default config/source.markdoc new file mode 100644 index 0000000..e9168db --- /dev/null +++ b/packages/process/tests/processor/default config/source.markdoc @@ -0,0 +1 @@ +# Hello World \ No newline at end of file diff --git a/packages/process/tests/processor/frontmatter export/compiled.txt b/packages/process/tests/processor/frontmatter export/compiled.txt new file mode 100644 index 0000000..b140207 --- /dev/null +++ b/packages/process/tests/processor/frontmatter export/compiled.txt @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/packages/process/tests/processor/frontmatter export/config.mjs b/packages/process/tests/processor/frontmatter export/config.mjs new file mode 100644 index 0000000..fc0d6f3 --- /dev/null +++ b/packages/process/tests/processor/frontmatter export/config.mjs @@ -0,0 +1,3 @@ +import { markdoc } from '../../../dist/module.js'; + +export default markdoc(); diff --git a/packages/process/tests/processor/frontmatter export/source.markdoc b/packages/process/tests/processor/frontmatter export/source.markdoc new file mode 100644 index 0000000..941c679 --- /dev/null +++ b/packages/process/tests/processor/frontmatter export/source.markdoc @@ -0,0 +1,5 @@ +--- +lorem: ipsum +--- + +# Hello World \ No newline at end of file diff --git a/packages/process/tests/processor/layout - default/compiled.txt b/packages/process/tests/processor/layout - default/compiled.txt new file mode 100644 index 0000000..6734945 --- /dev/null +++ b/packages/process/tests/processor/layout - default/compiled.txt @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/packages/process/tests/processor/layout - default/config.mjs b/packages/process/tests/processor/layout - default/config.mjs new file mode 100644 index 0000000..f33eebd --- /dev/null +++ b/packages/process/tests/processor/layout - default/config.mjs @@ -0,0 +1,9 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + layouts: { + default: absoulute(import.meta.url, '../../layouts/default.svelte'), + named: absoulute(import.meta.url, '../../layouts/named.svelte'), + }, +}); diff --git a/packages/process/tests/processor/layout - default/source.markdoc b/packages/process/tests/processor/layout - default/source.markdoc new file mode 100644 index 0000000..e9168db --- /dev/null +++ b/packages/process/tests/processor/layout - default/source.markdoc @@ -0,0 +1 @@ +# Hello World \ No newline at end of file diff --git a/packages/process/tests/processor/layout - named/compiled.txt b/packages/process/tests/processor/layout - named/compiled.txt new file mode 100644 index 0000000..257b6c6 --- /dev/null +++ b/packages/process/tests/processor/layout - named/compiled.txt @@ -0,0 +1 @@ +

Hello World

\ No newline at end of file diff --git a/packages/process/tests/processor/layout - named/config.mjs b/packages/process/tests/processor/layout - named/config.mjs new file mode 100644 index 0000000..f33eebd --- /dev/null +++ b/packages/process/tests/processor/layout - named/config.mjs @@ -0,0 +1,9 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + layouts: { + default: absoulute(import.meta.url, '../../layouts/default.svelte'), + named: absoulute(import.meta.url, '../../layouts/named.svelte'), + }, +}); diff --git a/packages/process/tests/processor/layout - named/source.markdoc b/packages/process/tests/processor/layout - named/source.markdoc new file mode 100644 index 0000000..753d112 --- /dev/null +++ b/packages/process/tests/processor/layout - named/source.markdoc @@ -0,0 +1,5 @@ +--- +layout: named +--- + +# Hello World \ No newline at end of file diff --git a/packages/process/tests/processor/nodes, tags and partials/compiled.txt b/packages/process/tests/processor/nodes, tags and partials/compiled.txt new file mode 100644 index 0000000..2ba2422 --- /dev/null +++ b/packages/process/tests/processor/nodes, tags and partials/compiled.txt @@ -0,0 +1 @@ +
Heading 1Heading 2With ID With Class

slot content

I am a partialLorem IpsumI am nested
\ No newline at end of file diff --git a/packages/process/tests/processor/nodes, tags and partials/config.mjs b/packages/process/tests/processor/nodes, tags and partials/config.mjs new file mode 100644 index 0000000..45b7220 --- /dev/null +++ b/packages/process/tests/processor/nodes, tags and partials/config.mjs @@ -0,0 +1,8 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + tags: absoulute(import.meta.url, '../../tags/module.svelte'), + nodes: absoulute(import.meta.url, '../../nodes/module.svelte'), + partials: absoulute(import.meta.url, '../../partials'), +}); diff --git a/packages/process/tests/processor/nodes, tags and partials/source.markdoc b/packages/process/tests/processor/nodes, tags and partials/source.markdoc new file mode 100644 index 0000000..4084e4a --- /dev/null +++ b/packages/process/tests/processor/nodes, tags and partials/source.markdoc @@ -0,0 +1,21 @@ +# Heading 1 + +## Heading 2 + +# With ID {% #my-id %} + +# With Class{% .my-class %} + +{% hello /%} + +{% slot %}slot content{% /slot %} + +{% unknown /%} + +{% partial file="test.md" /%} + +{% partial file="variables.md" variables={lorem: "Lorem", ipsum: "Ipsum"} /%} + +{% partial file="nested/file.md" /%} + +{% partial file="unknown.md" /%} \ No newline at end of file diff --git a/packages/process/tests/processor/nodes/compiled.txt b/packages/process/tests/processor/nodes/compiled.txt new file mode 100644 index 0000000..17b07af --- /dev/null +++ b/packages/process/tests/processor/nodes/compiled.txt @@ -0,0 +1 @@ +
Heading 1Heading 2With ID With Class
\ No newline at end of file diff --git a/packages/process/tests/processor/nodes/config.mjs b/packages/process/tests/processor/nodes/config.mjs new file mode 100644 index 0000000..80ae0d7 --- /dev/null +++ b/packages/process/tests/processor/nodes/config.mjs @@ -0,0 +1,6 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + nodes: absoulute(import.meta.url, '../../nodes/module.svelte'), +}); diff --git a/packages/process/tests/processor/nodes/source.markdoc b/packages/process/tests/processor/nodes/source.markdoc new file mode 100644 index 0000000..7cc1d95 --- /dev/null +++ b/packages/process/tests/processor/nodes/source.markdoc @@ -0,0 +1,7 @@ +# Heading 1 + +## Heading 2 + +# With ID {% #my-id %} + +# With Class{% .my-class %} \ No newline at end of file diff --git a/packages/process/tests/processor/partials/compiled.txt b/packages/process/tests/processor/partials/compiled.txt new file mode 100644 index 0000000..66a9231 --- /dev/null +++ b/packages/process/tests/processor/partials/compiled.txt @@ -0,0 +1 @@ +

I am a partial

Lorem Ipsum

I am nested

\ No newline at end of file diff --git a/packages/process/tests/processor/partials/config.mjs b/packages/process/tests/processor/partials/config.mjs new file mode 100644 index 0000000..b745987 --- /dev/null +++ b/packages/process/tests/processor/partials/config.mjs @@ -0,0 +1,6 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + partials: absoulute(import.meta.url, '../../partials'), +}); diff --git a/packages/process/tests/processor/partials/source.markdoc b/packages/process/tests/processor/partials/source.markdoc new file mode 100644 index 0000000..ac0fda5 --- /dev/null +++ b/packages/process/tests/processor/partials/source.markdoc @@ -0,0 +1,7 @@ +{% partial file="test.md" /%} + +{% partial file="variables.md" variables={lorem: "Lorem", ipsum: "Ipsum"} /%} + +{% partial file="nested/file.md" /%} + +{% partial file="unknown.md" /%} \ No newline at end of file diff --git a/packages/process/tests/processor/tags/compiled.txt b/packages/process/tests/processor/tags/compiled.txt new file mode 100644 index 0000000..fab4c12 --- /dev/null +++ b/packages/process/tests/processor/tags/compiled.txt @@ -0,0 +1 @@ +

slot content

\ No newline at end of file diff --git a/packages/process/tests/processor/tags/config.mjs b/packages/process/tests/processor/tags/config.mjs new file mode 100644 index 0000000..f624b39 --- /dev/null +++ b/packages/process/tests/processor/tags/config.mjs @@ -0,0 +1,6 @@ +import { markdoc } from '../../../dist/module.js'; +import { absoulute } from '../../utils.mjs'; + +export default markdoc({ + tags: absoulute(import.meta.url, '../../tags/module.svelte'), +}); diff --git a/packages/process/tests/processor/tags/source.markdoc b/packages/process/tests/processor/tags/source.markdoc new file mode 100644 index 0000000..cc56989 --- /dev/null +++ b/packages/process/tests/processor/tags/source.markdoc @@ -0,0 +1,5 @@ +{% hello /%} + +{% slot %}slot content{% /slot %} + +{% unknown /%} \ No newline at end of file diff --git a/packages/process/tests/utils.mjs b/packages/process/tests/utils.mjs index 687d1a7..e713429 100644 --- a/packages/process/tests/utils.mjs +++ b/packages/process/tests/utils.mjs @@ -1,6 +1,13 @@ +import { readFile } from 'fs/promises'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; export function absoulute(current, file) { return join(dirname(fileURLToPath(current)), file); } + +export function read_file(file) { + return readFile(file, { + encoding: 'utf8', + }); +}