diff --git a/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts b/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts index a9bcfd7631..a1f36cbd0f 100644 --- a/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts +++ b/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts @@ -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'); }); }); diff --git a/packages/backend-plugin-manager/src/scanner/plugin-scanner.test.ts b/packages/backend-plugin-manager/src/scanner/plugin-scanner.test.ts index 25f07baeaa..4891749a0b 100644 --- a/packages/backend-plugin-manager/src/scanner/plugin-scanner.test.ts +++ b/packages/backend-plugin-manager/src/scanner/plugin-scanner.test.ts @@ -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'), }, }, ], diff --git a/packages/core-app-api/src/app/defaultConfigLoader.test.ts b/packages/core-app-api/src/app/defaultConfigLoader.test.ts index 7579e53dd2..c70ec3fbff 100644 --- a/packages/core-app-api/src/app/defaultConfigLoader.test.ts +++ b/packages/core-app-api/src/app/defaultConfigLoader.test.ts @@ -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', ); }); diff --git a/packages/create-app/src/lib/tasks.test.ts b/packages/create-app/src/lib/tasks.test.ts index 95ced49490..c94bf43598 100644 --- a/packages/create-app/src/lib/tasks.test.ts +++ b/packages/create-app/src/lib/tasks.test.ts @@ -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"'); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.examples.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.examples.test.ts index c4c27cc68e..5139469959 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.examples.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.examples.test.ts @@ -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); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts index b12e4269c2..6804c9f5a9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts @@ -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); }); diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index e20e20ea5b..4d422d7125 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -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', ); });