Merge pull request #22829 from backstage/renovate/fs-extra-11.x
Update dependency fs-extra to v11
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"globby": "^11.0.0",
|
||||
"helmet": "^6.0.0",
|
||||
"knex": "^3.0.0",
|
||||
|
||||
@@ -14,29 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { injectConfig } from './config';
|
||||
|
||||
jest.mock('fs-extra');
|
||||
|
||||
const fsMock = fs as jest.Mocked<typeof fs>;
|
||||
const readFileMock = fsMock.readFile as unknown as jest.MockedFunction<
|
||||
(name: string) => Promise<string>
|
||||
>;
|
||||
|
||||
const MOCK_DIR = 'mock-dir';
|
||||
|
||||
const baseOptions = {
|
||||
appConfigs: [],
|
||||
staticDir: MOCK_DIR,
|
||||
logger: getVoidLogger(),
|
||||
};
|
||||
|
||||
describe('injectConfig', () => {
|
||||
const mockDir = createMockDirectory();
|
||||
|
||||
const baseOptions = {
|
||||
appConfigs: [],
|
||||
staticDir: mockDir.path,
|
||||
logger: getVoidLogger(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
fsMock.readdir.mockResolvedValue(['main.js'] as any);
|
||||
mockDir.clear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -44,185 +36,103 @@ describe('injectConfig', () => {
|
||||
});
|
||||
|
||||
it('should inject without config', async () => {
|
||||
fsMock.readdir.mockResolvedValue(['main.js'] as any);
|
||||
readFileMock.mockImplementation(
|
||||
async () => '"__APP_INJECTED_RUNTIME_CONFIG__"',
|
||||
);
|
||||
await injectConfig(baseOptions);
|
||||
expect(fsMock.readdir).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.readFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/',
|
||||
'utf8',
|
||||
);
|
||||
mockDir.setContent({
|
||||
'main.js': '"__APP_INJECTED_RUNTIME_CONFIG__"',
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(JSON.parse(eval(fsMock.writeFile.mock.calls[0][1]))).toEqual([]);
|
||||
await injectConfig(baseOptions);
|
||||
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js': '/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/',
|
||||
});
|
||||
});
|
||||
|
||||
it('should inject config repeatedly if marker appears multiple times', async () => {
|
||||
fsMock.readdir.mockResolvedValue(['main.js'] as any);
|
||||
readFileMock.mockImplementation(
|
||||
async () =>
|
||||
mockDir.setContent({
|
||||
'main.js':
|
||||
'({a:"__APP_INJECTED_RUNTIME_CONFIG__",b:"__APP_INJECTED_RUNTIME_CONFIG__"})',
|
||||
);
|
||||
await injectConfig(baseOptions);
|
||||
expect(fsMock.readdir).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.readFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'({a:/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/,b:/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/})',
|
||||
'utf8',
|
||||
);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(JSON.parse(eval(fsMock.writeFile.mock.calls[0][1]).a)).toEqual([]);
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(JSON.parse(eval(fsMock.writeFile.mock.calls[0][1]).b)).toEqual([]);
|
||||
await injectConfig(baseOptions);
|
||||
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js':
|
||||
'({a:/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/,b:/*__APP_INJECTED_CONFIG_MARKER__*/"[]"/*__INJECTED_END__*/})',
|
||||
});
|
||||
});
|
||||
|
||||
it('should find the correct file to inject', async () => {
|
||||
fsMock.readdir.mockResolvedValue([
|
||||
'before.js',
|
||||
'not-js.txt',
|
||||
'main.js',
|
||||
'after.js',
|
||||
] as any);
|
||||
readFileMock.mockImplementation(async (file: string) => {
|
||||
if (file.endsWith('main.js')) {
|
||||
return '"__APP_INJECTED_RUNTIME_CONFIG__"';
|
||||
}
|
||||
return 'NO_PLACEHOLDER_HERE';
|
||||
mockDir.setContent({
|
||||
'before.js': 'NO_PLACEHOLDER_HERE',
|
||||
'not-js.txt': 'NO_PLACEHOLDER_HERE',
|
||||
'main.js': '"__APP_INJECTED_RUNTIME_CONFIG__"',
|
||||
'after.js': 'NO_PLACEHOLDER_HERE',
|
||||
});
|
||||
|
||||
await injectConfig({
|
||||
...baseOptions,
|
||||
appConfigs: [{ data: { x: 0 }, context: 'test' }],
|
||||
});
|
||||
expect(fsMock.readFile).toHaveBeenCalledTimes(2);
|
||||
expect(fsMock.readFile).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
resolvePath(MOCK_DIR, 'before.js'),
|
||||
'utf8',
|
||||
);
|
||||
expect(fsMock.readFile).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(JSON.parse(eval(fsMock.writeFile.mock.calls[0][1]))).toEqual([
|
||||
{
|
||||
data: {
|
||||
x: 0,
|
||||
},
|
||||
context: 'test',
|
||||
},
|
||||
]);
|
||||
expect(mockDir.content()).toEqual({
|
||||
'before.js': 'NO_PLACEHOLDER_HERE',
|
||||
'not-js.txt': 'NO_PLACEHOLDER_HERE',
|
||||
'main.js':
|
||||
'/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/',
|
||||
'after.js': 'NO_PLACEHOLDER_HERE',
|
||||
});
|
||||
});
|
||||
|
||||
it('should re-inject config', async () => {
|
||||
fsMock.readdir.mockResolvedValue(['main.js'] as any);
|
||||
readFileMock.mockResolvedValue(
|
||||
'JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__")',
|
||||
);
|
||||
mockDir.setContent({
|
||||
'main.js': 'JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__")',
|
||||
});
|
||||
|
||||
await injectConfig({
|
||||
...baseOptions,
|
||||
appConfigs: [{ data: { x: 0 }, context: 'test' }],
|
||||
});
|
||||
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/)',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[0][1])).toEqual([
|
||||
{ data: { x: 0 }, context: 'test' },
|
||||
]);
|
||||
|
||||
readFileMock.mockResolvedValue(fsMock.writeFile.mock.calls[0][1]);
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js':
|
||||
'JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/)',
|
||||
});
|
||||
|
||||
await injectConfig({
|
||||
...baseOptions,
|
||||
appConfigs: [{ data: { x: 1, y: 2 }, context: 'test' }],
|
||||
});
|
||||
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(2);
|
||||
expect(fsMock.writeFile).toHaveBeenLastCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/)',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[1][1])).toEqual([
|
||||
{ data: { x: 1, y: 2 }, context: 'test' },
|
||||
]);
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js':
|
||||
'JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/)',
|
||||
});
|
||||
});
|
||||
|
||||
it('should re-inject config repeatedly if needed', async () => {
|
||||
fsMock.readdir.mockResolvedValue(['main.js'] as any);
|
||||
readFileMock.mockResolvedValue(
|
||||
'({ a: JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__"), b: JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__") })',
|
||||
);
|
||||
mockDir.setContent({
|
||||
'main.js':
|
||||
'({ a: JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__"), b: JSON.parse("__APP_INJECTED_RUNTIME_CONFIG__") })',
|
||||
});
|
||||
|
||||
await injectConfig({
|
||||
...baseOptions,
|
||||
appConfigs: [{ data: { x: 0 }, context: 'test' }],
|
||||
});
|
||||
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(1);
|
||||
expect(fsMock.writeFile).toHaveBeenCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'({ a: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/), b: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/) })',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[0][1]).a).toEqual([
|
||||
{ data: { x: 0 }, context: 'test' },
|
||||
]);
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[0][1]).b).toEqual([
|
||||
{ data: { x: 0 }, context: 'test' },
|
||||
]);
|
||||
|
||||
readFileMock.mockResolvedValue(fsMock.writeFile.mock.calls[0][1]);
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js':
|
||||
'({ a: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/), b: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":0},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/) })',
|
||||
});
|
||||
|
||||
await injectConfig({
|
||||
...baseOptions,
|
||||
appConfigs: [{ data: { x: 1, y: 2 }, context: 'test' }],
|
||||
});
|
||||
|
||||
expect(fsMock.writeFile).toHaveBeenCalledTimes(2);
|
||||
expect(fsMock.writeFile).toHaveBeenLastCalledWith(
|
||||
resolvePath(MOCK_DIR, 'main.js'),
|
||||
'({ a: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/), b: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/) })',
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[1][1]).a).toEqual([
|
||||
{ data: { x: 1, y: 2 }, context: 'test' },
|
||||
]);
|
||||
// eslint-disable-next-line no-eval
|
||||
expect(eval(fsMock.writeFile.mock.calls[1][1]).b).toEqual([
|
||||
{ data: { x: 1, y: 2 }, context: 'test' },
|
||||
]);
|
||||
expect(mockDir.content()).toEqual({
|
||||
'main.js':
|
||||
'({ a: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/), b: JSON.parse(/*__APP_INJECTED_CONFIG_MARKER__*/"[{\\"data\\":{\\"x\\":1,\\"y\\":2},\\"context\\":\\"test\\"}]"/*__INJECTED_END__*/) })',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,6 @@
|
||||
"@backstage/config-loader": "workspace:^",
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1",
|
||||
"fs-extra": "10.1.0"
|
||||
"fs-extra": "^11.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"express-session": "^1.17.1",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"google-auth-library": "^8.0.0",
|
||||
"jose": "^4.6.0",
|
||||
"knex": "^3.0.0",
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@backstage/integration": "workspace:^",
|
||||
"@backstage/plugin-catalog-node": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"uuid": "^8.0.0",
|
||||
"winston": "^3.2.1"
|
||||
@@ -56,7 +56,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/fs-extra": "^11.0.0",
|
||||
"luxon": "^3.0.0",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
"core-js": "^3.6.5",
|
||||
"express": "^4.17.1",
|
||||
"fast-json-stable-stringify": "^2.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"git-url-parse": "^14.0.0",
|
||||
"glob": "^7.1.6",
|
||||
"knex": "^3.0.0",
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"@yarnpkg/parsers": "^3.0.0-rc.4",
|
||||
"express": "^4.18.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"fs-extra": "^11.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"node-fetch": "^2.6.7",
|
||||
"ping": "^0.4.1",
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"helmet": "^6.0.0",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"@types/express": "*",
|
||||
"express": "^4.18.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"fs-extra": "^11.0.0",
|
||||
"knex": "^3.0.0",
|
||||
"linguist-js": "^2.5.3",
|
||||
"luxon": "^2.0.2",
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"morgan": "^1.10.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@backstage/integration": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"yaml": "^2.0.0"
|
||||
},
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@backstage/integration": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"yaml": "^2.0.0"
|
||||
},
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
"@backstage/plugin-scaffolder-backend-module-bitbucket-cloud": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-backend-module-bitbucket-server": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"yaml": "^2.0.0"
|
||||
},
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@backstage/integration": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"git-url-parse": "^14.0.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
"command-exists": "^1.2.9",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
@@ -54,7 +54,7 @@
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/command-exists": "^1.2.0",
|
||||
"@types/fs-extra": "^9.0.1"
|
||||
"@types/fs-extra": "^11.0.0"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/libsodium-wrappers": "^0.7.10",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"jest-when": "^3.1.0",
|
||||
"jsonschema": "^1.2.6"
|
||||
},
|
||||
|
||||
@@ -46,13 +46,13 @@
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
"command-exists": "^1.2.9",
|
||||
"fs-extra": "^10.0.1"
|
||||
"fs-extra": "^11.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/command-exists": "^1.2.0",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/fs-extra": "^11.0.0",
|
||||
"@types/node": "^18.17.8",
|
||||
"jest-when": "^3.1.0"
|
||||
},
|
||||
|
||||
+54
-33
@@ -26,21 +26,23 @@ jest.mock(
|
||||
(...args: any[]) =>
|
||||
commandExists(...args),
|
||||
);
|
||||
jest.mock('fs-extra');
|
||||
|
||||
import { ContainerRunner } from '@backstage/backend-common';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { PassThrough } from 'stream';
|
||||
import { RailsNewRunner } from './railsNewRunner';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
describe('Rails Templater', () => {
|
||||
const containerRunner: jest.Mocked<ContainerRunner> = {
|
||||
runContainer: jest.fn(),
|
||||
};
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockDir.clear();
|
||||
});
|
||||
|
||||
describe('when running on docker', () => {
|
||||
@@ -53,14 +55,15 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
jest
|
||||
.spyOn(fs, 'realpath')
|
||||
.mockImplementation(x => Promise.resolve(x.toString()));
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream,
|
||||
});
|
||||
@@ -71,8 +74,8 @@ describe('Rails Templater', () => {
|
||||
args: ['new', '/output/rails-project'],
|
||||
envVars: { HOME: '/tmp' },
|
||||
mountDirs: {
|
||||
['tempdir']: '/input',
|
||||
[path.join('tempdir', 'intermediate')]: '/output',
|
||||
[mockDir.path]: '/input',
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: logStream,
|
||||
@@ -88,11 +91,15 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream,
|
||||
});
|
||||
@@ -114,11 +121,15 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream: stream,
|
||||
});
|
||||
@@ -129,8 +140,8 @@ describe('Rails Templater', () => {
|
||||
args: ['new', '/output/rails-project'],
|
||||
envVars: { HOME: '/tmp' },
|
||||
mountDirs: {
|
||||
['tempdir']: '/input',
|
||||
[path.join('tempdir', 'intermediate')]: '/output',
|
||||
[mockDir.path]: '/input',
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: stream,
|
||||
@@ -147,14 +158,15 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
jest
|
||||
.spyOn(fs, 'realpath')
|
||||
.mockImplementation(x => Promise.resolve(x.toString()));
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream,
|
||||
});
|
||||
@@ -170,8 +182,8 @@ describe('Rails Templater', () => {
|
||||
],
|
||||
envVars: { HOME: '/tmp' },
|
||||
mountDirs: {
|
||||
['tempdir']: '/input',
|
||||
[path.join('tempdir', 'intermediate')]: '/output',
|
||||
[mockDir.path]: '/input',
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: logStream,
|
||||
@@ -190,12 +202,16 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
commandExists.mockImplementationOnce(() => () => true);
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream: stream,
|
||||
});
|
||||
@@ -204,11 +220,12 @@ describe('Rails Templater', () => {
|
||||
command: 'rails',
|
||||
args: expect.arrayContaining([
|
||||
'new',
|
||||
path.join('tempdir', 'intermediate', 'rails-project'),
|
||||
path.join(mockDir.path, 'intermediate', 'rails-project'),
|
||||
]),
|
||||
logStream: stream,
|
||||
});
|
||||
});
|
||||
|
||||
it('update the template path to correct location', async () => {
|
||||
const stream = new PassThrough();
|
||||
|
||||
@@ -220,12 +237,16 @@ describe('Rails Templater', () => {
|
||||
imageName: 'foo/rails-custom-image',
|
||||
};
|
||||
|
||||
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
|
||||
mockDir.setContent({
|
||||
intermediate: {
|
||||
fakeGeneratedOutput: 'a',
|
||||
},
|
||||
});
|
||||
commandExists.mockImplementationOnce(() => () => true);
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logStream: stream,
|
||||
});
|
||||
@@ -234,9 +255,9 @@ describe('Rails Templater', () => {
|
||||
command: 'rails',
|
||||
args: expect.arrayContaining([
|
||||
'new',
|
||||
path.join('tempdir', 'intermediate', 'rails-project'),
|
||||
path.join(mockDir.path, 'intermediate', 'rails-project'),
|
||||
'--template',
|
||||
path.join('tempdir', './something.rb'),
|
||||
path.join(mockDir.path, './something.rb'),
|
||||
]),
|
||||
logStream: stream,
|
||||
});
|
||||
@@ -247,14 +268,14 @@ describe('Rails Templater', () => {
|
||||
it('throws an error', async () => {
|
||||
const stream = new PassThrough();
|
||||
|
||||
jest
|
||||
.spyOn(fs, 'readdir')
|
||||
.mockImplementationOnce(() => Promise.resolve([]));
|
||||
mockDir.setContent({
|
||||
intermediate: {},
|
||||
});
|
||||
|
||||
const templater = new RailsNewRunner({ containerRunner });
|
||||
await expect(
|
||||
templater.run({
|
||||
workspacePath: 'tempdir',
|
||||
workspacePath: mockDir.path,
|
||||
values: {
|
||||
owner: 'angeliski',
|
||||
storePath: 'https://github.com/angeliski/rails-project',
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
"@types/luxon": "^3.0.0",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"globby": "^11.0.0",
|
||||
"isbinaryfile": "^5.0.0",
|
||||
"isolated-vm": "^4.5.0",
|
||||
@@ -94,7 +94,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/fs-extra": "^11.0.0",
|
||||
"@types/nunjucks": "^3.1.4",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"@types/zen-observable": "^0.8.0",
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"@backstage/integration": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-common": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"globby": "^11.0.0",
|
||||
"jsonschema": "^1.2.6",
|
||||
"p-limit": "^3.1.0",
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
"dockerode": "^3.3.1",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"knex": "^3.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"node-fetch": "^2.6.7",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"@trendyol-js/openstack-swift-sdk": "^0.0.7",
|
||||
"@types/express": "^4.17.6",
|
||||
"express": "^4.17.1",
|
||||
"fs-extra": "10.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"git-url-parse": "^14.0.0",
|
||||
"hpagent": "^1.2.0",
|
||||
"js-yaml": "^4.0.0",
|
||||
@@ -71,7 +71,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/fs-extra": "^9.0.5",
|
||||
"@types/fs-extra": "^11.0.0",
|
||||
"@types/js-yaml": "^4.0.0",
|
||||
"@types/mime-types": "^2.1.0",
|
||||
"@types/recursive-readdir": "^2.2.0",
|
||||
|
||||
Reference in New Issue
Block a user