test fixes for Node.js v20

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-31 21:11:13 +02:00
parent 47d73e401f
commit 6246571911
7 changed files with 29 additions and 29 deletions
@@ -85,8 +85,8 @@ describe('fs:rename examples', () => {
const sourceFilePath = resolvePath(workspacePath, sourceFile);
const destFilePath = resolvePath(workspacePath, destFile);
const sourceBeforeContent = fs.readFileSync(sourceFilePath, 'utf-8');
const destBeforeContent = fs.readFileSync(destFilePath, 'utf-8');
const sourceBeforeContent = await fs.readFile(sourceFilePath, 'utf-8');
const destBeforeContent = await fs.readFile(destFilePath, 'utf-8');
expect(sourceBeforeContent).not.toEqual(destBeforeContent);
@@ -97,7 +97,7 @@ describe('fs:rename examples', () => {
},
});
const destAfterContent = fs.readFileSync(destFilePath, 'utf-8');
const destAfterContent = await fs.readFile(destFilePath, 'utf-8');
expect(sourceBeforeContent).toEqual(destAfterContent);
});
@@ -148,7 +148,7 @@ describe('fs:rename', () => {
it('should throw is trying to override by mistake', async () => {
const destFile = 'unit-test-c.js';
const filePath = resolvePath(workspacePath, destFile);
const beforeContent = fs.readFileSync(filePath, 'utf-8');
const beforeContent = await fs.readFile(filePath, 'utf-8');
await expect(
action.handler({
@@ -164,7 +164,7 @@ describe('fs:rename', () => {
}),
).rejects.toThrow(/dest already exists/);
const afterContent = fs.readFileSync(filePath, 'utf-8');
const afterContent = await fs.readFile(filePath, 'utf-8');
expect(beforeContent).toEqual(afterContent);
});
@@ -191,8 +191,8 @@ describe('fs:rename', () => {
const sourceFilePath = resolvePath(workspacePath, sourceFile);
const destFilePath = resolvePath(workspacePath, destFile);
const sourceBeforeContent = fs.readFileSync(sourceFilePath, 'utf-8');
const destBeforeContent = fs.readFileSync(destFilePath, 'utf-8');
const sourceBeforeContent = await fs.readFile(sourceFilePath, 'utf-8');
const destBeforeContent = await fs.readFile(destFilePath, 'utf-8');
expect(sourceBeforeContent).not.toEqual(destBeforeContent);
@@ -209,7 +209,7 @@ describe('fs:rename', () => {
},
});
const destAfterContent = fs.readFileSync(destFilePath, 'utf-8');
const destAfterContent = await fs.readFile(destFilePath, 'utf-8');
expect(sourceBeforeContent).toEqual(destAfterContent);
});
@@ -393,7 +393,7 @@ describe('helpers', () => {
await patchIndexPreBuild({ inputDir: '/', logger: mockLogger });
expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual(
await expect(fs.readFile('/docs/index.md', 'utf-8')).resolves.toEqual(
'index.md content',
);
expect(warn).not.toHaveBeenCalledWith();
@@ -407,7 +407,7 @@ describe('helpers', () => {
await patchIndexPreBuild({ inputDir: '/', logger: mockLogger });
expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual(
await expect(fs.readFile('/docs/index.md', 'utf-8')).resolves.toEqual(
'docs/README.md content',
);
expect(warn.mock.calls).toEqual([
@@ -422,7 +422,7 @@ describe('helpers', () => {
await patchIndexPreBuild({ inputDir: '/', logger: mockLogger });
expect(fs.readFileSync('/docs/index.md', 'utf-8')).toEqual(
await expect(fs.readFile('/docs/index.md', 'utf-8')).resolves.toEqual(
'main README.md content',
);
expect(warn.mock.calls).toEqual([
@@ -437,7 +437,7 @@ describe('helpers', () => {
await patchIndexPreBuild({ inputDir: '/', logger: mockLogger });
expect(() => fs.readFileSync('/docs/index.md', 'utf-8')).toThrow();
await expect(fs.readFile('/docs/index.md', 'utf-8')).rejects.toThrow();
const paths = [
path.normalize('docs/index.md'),
path.normalize('docs/README.md'),
@@ -483,7 +483,7 @@ describe('helpers', () => {
await expect(
createOrUpdateMetadata(filePath, mockLogger),
).rejects.toThrow('Unexpected token d in JSON at position 0');
).rejects.toThrow('Unexpected token');
});
it('should add build timestamp to the metadata json', async () => {
@@ -520,7 +520,7 @@ describe('helpers', () => {
const filePath = path.join(rootDir, 'invalid_techdocs_metadata.json');
await expect(storeEtagMetadata(filePath, 'etag123abc')).rejects.toThrow(
'Unexpected token d in JSON at position 0',
'Unexpected token',
);
});