Merge pull request #20378 from backstage/rugvip/20-fixes

More fixes for node 20 test breakage + overridePackagePathResolution
This commit is contained in:
Patrik Oldsberg
2023-10-05 21:01:48 +02:00
committed by GitHub
25 changed files with 434 additions and 436 deletions
-1
View File
@@ -69,7 +69,6 @@
"@backstage/cli": "workspace:^",
"@backstage/types": "workspace:^",
"@types/supertest": "^2.0.8",
"mock-fs": "^5.2.0",
"msw": "^1.0.0",
"node-fetch": "^2.6.7",
"supertest": "^6.1.3"
@@ -14,40 +14,40 @@
* limitations under the License.
*/
import mockFs from 'mock-fs';
import { createMockDirectory } from '@backstage/backend-test-utils';
import { findStaticAssets } from './findStaticAssets';
describe('findStaticAssets', () => {
const mockDir = createMockDirectory();
afterEach(() => {
mockFs.restore();
mockDir.clear();
});
it('should find assets', async () => {
mockFs({
'/test': {
'a.js': 'alert("hello")',
'a.js.map': '',
'b.js': 'b',
'b.js.map': '',
js: {
'd.js': 'd',
'd.js.map': '',
x: {
mockDir.setContent({
'a.js': 'alert("hello")',
'a.js.map': '',
'b.js': 'b',
'b.js.map': '',
js: {
'd.js': 'd',
'd.js.map': '',
x: {
'e.map': '',
y: {
'e.map': '',
y: {
z: {
'e.js': 'e',
'e.map': '',
z: {
'e.js': 'e',
'e.map': '',
},
},
},
},
styles: { 'c.css': 'body { color: red; }' },
},
styles: { 'c.css': 'body { color: red; }' },
});
const assets = await findStaticAssets('/test');
const assets = await findStaticAssets(mockDir.path);
expect(assets.length).toBe(5);
expect(assets.map(a => a.path)).toEqual(
expect.arrayContaining([
@@ -14,33 +14,36 @@
* limitations under the License.
*/
import mockFs from 'mock-fs';
import { resolve as resolvePath } from 'path';
import fetch from 'node-fetch';
import { mockServices, startTestBackend } from '@backstage/backend-test-utils';
import {
createMockDirectory,
mockServices,
startTestBackend,
} from '@backstage/backend-test-utils';
import { appPlugin } from './appPlugin';
import { createRootLogger } from '@backstage/backend-common';
import { overridePackagePathResolution } from '@backstage/backend-common/testUtils';
const mockDir = createMockDirectory();
overridePackagePathResolution({
packageName: 'app',
path: mockDir.path,
});
// Make sure root logger is initialized ahead of FS mock
createRootLogger();
describe('appPlugin', () => {
beforeEach(() => {
mockFs({
[resolvePath(process.cwd(), 'node_modules/app')]: {
'package.json': '{}',
dist: {
static: {},
'index.html': 'winning',
},
mockDir.setContent({
'package.json': '{}',
dist: {
static: {},
'index.html': 'winning',
},
});
});
afterEach(() => {
mockFs.restore();
});
it('boots', async () => {
const { server } = await startTestBackend({
features: [