Skip to content

Commit 1ec6e26

Browse files
authored
Use node20 and build with ncc (#11)
1 parent bae16e3 commit 1ec6e26

File tree

673 files changed

+29526
-78678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

673 files changed

+29526
-78678
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
docs
2+
node_modules

__tests__/utils/file.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const filesStructure = require('../../utils/files');
4+
5+
jest.mock('fs');
6+
jest.mock('path');
7+
8+
describe('filesStructure', () => {
9+
it('returns structure of markdown files in directory and only select .md files', () => {
10+
// file1.md
11+
// file2.md
12+
// subdir/
13+
// file3.md
14+
// image.png
15+
// subdir_only_image/
16+
// image2.png
17+
const mockFiles = ['file1.md', 'file2.md', 'subdir/file3.md', 'subdir/image.png', 'subdir_only_image/image2.png'];
18+
fs.statSync.mockImplementation((file) => {
19+
return { isDirectory: () => !file.includes('.') };
20+
});
21+
22+
fs.readdirSync.mockReturnValue(mockFiles);
23+
path.join.mockImplementation((...args) => args.join('/'));
24+
25+
const result = filesStructure('root');
26+
27+
expect(result).toEqual([['file1.md'], ['file2.md'], ['subdir', 'file3.md']]);
28+
});
29+
30+
it('returns empty array when directory is empty', () => {
31+
fs.statSync.mockReturnValue({ isDirectory: () => true });
32+
fs.readdirSync.mockReturnValue([]);
33+
path.join.mockImplementation((...args) => args.join('/'));
34+
35+
const result = filesStructure('root');
36+
37+
expect(result).toEqual([]);
38+
});
39+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require('fs');
2+
const Marked = require('marked');
3+
const markdownForFile = require('../../utils/markdownToHtml');
4+
5+
jest.mock('fs');
6+
jest.mock('marked');
7+
8+
describe('markdownForFile', () => {
9+
it('reads file and parses markdown when file exists', (done) => {
10+
const mockData = '# Hello World';
11+
const mockHtml = '<h1 id="hello-world">Hello World</h1>\n';
12+
fs.readFile.mockImplementationOnce((path, options, cb) => cb(null, mockData));
13+
Marked.parse.mockImplementationOnce((data, cb) => cb(null, mockHtml));
14+
15+
markdownForFile('path/to/file', (err, data) => {
16+
expect(err).toBeNull();
17+
expect(data).toBe(mockHtml);
18+
done();
19+
});
20+
});
21+
22+
it('returns error when file does not exist', (done) => {
23+
const mockError = new Error('File not found');
24+
fs.readFile.mockImplementationOnce((path, options, cb) => cb(mockError));
25+
26+
markdownForFile('path/to/nonexistent/file', (err, data) => {
27+
expect(err).toEqual(mockError);
28+
expect(data).toBeUndefined();
29+
done();
30+
});
31+
});
32+
33+
it('returns error when markdown parsing fails', (done) => {
34+
const mockData = '# Hello World';
35+
const mockError = new Error('Markdown parsing error');
36+
fs.readFile.mockImplementationOnce((path, options, cb) => cb(null, mockData));
37+
Marked.parse.mockImplementationOnce((data, cb) => cb(mockError));
38+
39+
markdownForFile('path/to/file', (err, data) => {
40+
expect(err).toEqual(mockError);
41+
expect(data).toBeUndefined();
42+
done();
43+
});
44+
});
45+
});

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ inputs:
2424
description: "Page id under which the documentation will be published"
2525
required: true
2626
runs:
27-
using: "node16"
28-
main: "index.js"
27+
using: "node20"
28+
main: "dist/index.js"

0 commit comments

Comments
 (0)