Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 25 additions & 95 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"estree-util-to-js": "^2.0.0",
"estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"glob": "^11.0.3",
"globals": "^16.4.0",
"hast-util-to-string": "^3.0.1",
"hastscript": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/generators/ast-js/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
const { loadFiles } = createJsLoader();

// Load all of the Javascript sources into memory
const sourceFiles = loadFiles(options.input ?? []);
const sourceFiles = await loadFiles(options.input ?? []);

const { parseJsSources } = createJsParser();

Expand Down
43 changes: 43 additions & 0 deletions src/loaders/__tests__/javascript.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

import assert from 'node:assert/strict';
import { describe, it, mock } from 'node:test';

import { VFile } from 'vfile';

const fakeFiles = [
'/fake/path/file1.js',
'/fake/path/file2.js',
'/fake/path/not-a-js-file.txt',
];

const fakeContent = 'const a = 1;';

mock.module('node:fs', {
namedExports: {
globSync: () => fakeFiles,
},
});

mock.module('node:fs/promises', {
namedExports: {
readFile: () => Promise.resolve(fakeContent),
},
});

const createLoader = (await import('../javascript.mjs')).default;

describe('javascript-loader', () => {
it('should load javascript files into VFiles', async () => {
const loader = createLoader();
const vfiles = await loader.loadFiles('*.js');

assert.strictEqual(vfiles.length, 2); // Ignored the .txt file

assert.ok(vfiles[0] instanceof VFile);
assert.strictEqual(vfiles[0].path, fakeFiles[0]);
assert.strictEqual(vfiles[0].value, fakeContent);
assert.strictEqual(vfiles[1].path, fakeFiles[1]);
assert.strictEqual(vfiles[1].value, fakeContent);
});
});
Loading
Loading