test fixes for Node.js v20
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -72,11 +72,11 @@ describe('ReadableArrayResponse', () => {
|
||||
const res = new ReadableArrayResponse(arr, '/tmp', 'etag');
|
||||
const dir = await res.dir();
|
||||
|
||||
expect(fs.readFileSync(resolvePath(dir, 'file1.yaml'), 'utf8').trim()).toBe(
|
||||
'site_name: Test',
|
||||
);
|
||||
expect(fs.readFileSync(resolvePath(dir, 'file2.yaml'), 'utf8').trim()).toBe(
|
||||
'site_name: Test2',
|
||||
);
|
||||
await expect(
|
||||
fs.readFile(resolvePath(dir, 'file1.yaml'), 'utf8'),
|
||||
).resolves.toBe('site_name: Test\n');
|
||||
await expect(
|
||||
fs.readFile(resolvePath(dir, 'file2.yaml'), 'utf8'),
|
||||
).resolves.toBe('site_name: Test2\n');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -571,7 +571,7 @@ Please add '/backstageRoot/node_modules' to the 'NODE_PATH' when running the bac
|
||||
"failed to load dynamic plugin manifest from '/backstageRoot/dist-dynamic/test-backend-plugin/alpha'",
|
||||
meta: {
|
||||
name: 'SyntaxError',
|
||||
message: 'Unexpected token i in JSON at position 0',
|
||||
message: expect.stringContaining('Unexpected token'),
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -604,7 +604,7 @@ Please add '/backstageRoot/node_modules' to the 'NODE_PATH' when running the bac
|
||||
"failed to load dynamic plugin manifest from '/backstageRoot/dist-dynamic/test-backend-plugin'",
|
||||
meta: {
|
||||
name: 'SyntaxError',
|
||||
message: 'Unexpected token i in JSON at position 0',
|
||||
message: expect.stringContaining('Unexpected token'),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('defaultConfigLoaderSync', () => {
|
||||
anyEnv.APP_CONFIG = [{ data: { my: 'config' }, context: 'a' }];
|
||||
|
||||
expect(() => defaultConfigLoaderSync('}')).toThrow(
|
||||
'Failed to load runtime configuration, SyntaxError: Unexpected token } in JSON at position 0',
|
||||
'Failed to load runtime configuration, SyntaxError: Unexpected token',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -304,13 +304,13 @@ describe('tasks', () => {
|
||||
},
|
||||
);
|
||||
// catalog was populated with `context.name`
|
||||
expect(
|
||||
fs.readFileSync('templatedApp/catalog-info.yaml', 'utf-8'),
|
||||
).toContain('name: SuperCoolBackstageInstance');
|
||||
await expect(
|
||||
fs.readFile('templatedApp/catalog-info.yaml', 'utf-8'),
|
||||
).resolves.toContain('name: SuperCoolBackstageInstance');
|
||||
// backend dependencies include `sqlite3` from `context.SQLite`
|
||||
expect(
|
||||
fs.readFileSync('templatedApp/packages/backend/package.json', 'utf-8'),
|
||||
).toContain('sqlite3"');
|
||||
await expect(
|
||||
fs.readFile('templatedApp/packages/backend/package.json', 'utf-8'),
|
||||
).resolves.toContain('sqlite3"');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -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',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user