mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-13 14:56:54 +08:00
chore(build): Refactor writeBuildArtifact function.
This commit is contained in:
parent
417f5cb004
commit
a6f39fbcd0
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,7 +21,6 @@ packages/server-dev/build/**
|
||||
|
||||
.DS_Store
|
||||
|
||||
packages/build/src/test/writeFile.txt
|
||||
packages/build/build/**
|
||||
|
||||
packages/plugins/connections/connection-mongodb/mongod-*
|
||||
|
@ -17,7 +17,7 @@
|
||||
import { cleanDirectory } from '@lowdefy/node-utils';
|
||||
|
||||
async function cleanBuildDirectory({ context }) {
|
||||
return cleanDirectory(context.directories.build);
|
||||
await cleanDirectory(context.directories.build);
|
||||
}
|
||||
|
||||
export default cleanBuildDirectory;
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeApp({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'app.json',
|
||||
content: JSON.stringify(components.app || {}, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('app.json', JSON.stringify(components.app || {}, null, 2));
|
||||
}
|
||||
|
||||
export default writeApp;
|
||||
|
@ -34,12 +34,10 @@ test('writeApp', async () => {
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{
|
||||
'app.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,25 +47,11 @@ test('writeApp empty config', async () => {
|
||||
app: {},
|
||||
};
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['app.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeApp config undefined', async () => {
|
||||
const components = {};
|
||||
await writeApp({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'app.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['app.json', `{}`]]);
|
||||
});
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeConfig({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'config.json',
|
||||
content: JSON.stringify(components.config || {}, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('config.json', JSON.stringify(components.config || {}, null, 2));
|
||||
}
|
||||
|
||||
export default writeConfig;
|
||||
|
@ -34,12 +34,10 @@ test('writeConfig', async () => {
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{
|
||||
'config.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,25 +47,11 @@ test('writeConfig empty config', async () => {
|
||||
config: {},
|
||||
};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['config.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeConfig config undefined', async () => {
|
||||
const components = {};
|
||||
await writeConfig({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'config.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['config.json', `{}`]]);
|
||||
});
|
||||
|
@ -22,10 +22,10 @@ async function writeConnections({ components, context }) {
|
||||
throw new Error(`Connections is not an array.`);
|
||||
}
|
||||
const writePromises = components.connections.map(async (connection) => {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `connections/${connection.connectionId}.json`,
|
||||
content: JSON.stringify(connection, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`connections/${connection.connectionId}.json`,
|
||||
JSON.stringify(connection, null, 2)
|
||||
);
|
||||
});
|
||||
return Promise.all(writePromises);
|
||||
}
|
||||
|
@ -40,16 +40,14 @@ test('writeConnections write connection', async () => {
|
||||
await writeConnections({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection1.json',
|
||||
content: `{
|
||||
'connections/connection1.json',
|
||||
`{
|
||||
"id": "connection:connection1",
|
||||
"connectionId": "connection1",
|
||||
"properties": {
|
||||
"prop": "val"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -70,22 +68,18 @@ test('writeConnections multiple connection', async () => {
|
||||
await writeConnections({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection1.json',
|
||||
content: `{
|
||||
'connections/connection1.json',
|
||||
`{
|
||||
"id": "connection:connection1",
|
||||
"connectionId": "connection1"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'connections/connection2.json',
|
||||
content: `{
|
||||
'connections/connection2.json',
|
||||
`{
|
||||
"id": "connection:connection2",
|
||||
"connectionId": "connection2"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -23,10 +23,7 @@ async function writeGlobal({ components, context }) {
|
||||
if (!type.isObject(components.global)) {
|
||||
throw new Error('Global is not an object.');
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'global.json',
|
||||
content: JSON.stringify(components.global, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('global.json', JSON.stringify(components.global, null, 2));
|
||||
}
|
||||
|
||||
export default writeGlobal;
|
||||
|
@ -34,12 +34,10 @@ test('writeGlobal', async () => {
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{
|
||||
'global.json',
|
||||
`{
|
||||
"key": "value"
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -49,27 +47,13 @@ test('writeGlobal empty global', async () => {
|
||||
global: {},
|
||||
};
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['global.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeGlobal global undefined', async () => {
|
||||
const components = {};
|
||||
await writeGlobal({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'global.json',
|
||||
content: `{}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['global.json', `{}`]]);
|
||||
});
|
||||
|
||||
test('writeGlobal global not an object', async () => {
|
||||
|
@ -20,10 +20,7 @@ async function writeMenus({ components, context }) {
|
||||
if (!type.isArray(components.menus)) {
|
||||
throw new Error('Menus is not an array.');
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'menus.json',
|
||||
content: JSON.stringify(components.menus, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('menus.json', JSON.stringify(components.menus, null, 2));
|
||||
}
|
||||
|
||||
export default writeMenus;
|
||||
|
@ -38,16 +38,14 @@ test('writeMenus', async () => {
|
||||
await writeMenus({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'menus.json',
|
||||
content: `[
|
||||
'menus.json',
|
||||
`[
|
||||
{
|
||||
"id": "menu:default",
|
||||
"menuId": "default",
|
||||
"links": []
|
||||
}
|
||||
]`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -57,14 +55,7 @@ test('writeMenus empty menus', async () => {
|
||||
menus: [],
|
||||
};
|
||||
await writeMenus({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'menus.json',
|
||||
content: `[]`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([['menus.json', `[]`]]);
|
||||
});
|
||||
|
||||
test('writeMenus menus undefined', async () => {
|
||||
|
@ -20,10 +20,10 @@ async function writePage({ page, context }) {
|
||||
if (!type.isObject(page)) {
|
||||
throw new Error(`Page is not an object. Received ${JSON.stringify(page)}`);
|
||||
}
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `pages/${page.pageId}/${page.pageId}.json`,
|
||||
content: JSON.stringify(page, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`pages/${page.pageId}/${page.pageId}.json`,
|
||||
JSON.stringify(page, null, 2)
|
||||
);
|
||||
}
|
||||
|
||||
async function writePages({ components, context }) {
|
||||
|
@ -39,15 +39,13 @@ test('writePages write page', async () => {
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/page1.json',
|
||||
content: `{
|
||||
'pages/page1/page1.json',
|
||||
`{
|
||||
"id": "page:page1",
|
||||
"pageId": "page1",
|
||||
"blockId": "page1",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -72,26 +70,22 @@ test('writePages multiple pages', async () => {
|
||||
await writePages({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/page1.json',
|
||||
content: `{
|
||||
'pages/page1/page1.json',
|
||||
`{
|
||||
"id": "page:page1",
|
||||
"pageId": "page1",
|
||||
"blockId": "page1",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page2/page2.json',
|
||||
content: `{
|
||||
'pages/page2/page2.json',
|
||||
`{
|
||||
"id": "page:page2",
|
||||
"pageId": "page2",
|
||||
"blockId": "page2",
|
||||
"requests": []
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -17,13 +17,13 @@
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeBlockImports({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/blocks.js',
|
||||
content: generateImportFile({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/blocks.js',
|
||||
generateImportFile({
|
||||
types: components.types.blocks,
|
||||
importPath: 'blocks',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeBlockImports;
|
||||
|
@ -17,13 +17,13 @@
|
||||
import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeConnectionImports({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/connections.js',
|
||||
content: generateImportFile({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/connections.js',
|
||||
generateImportFile({
|
||||
types: components.types.connections,
|
||||
importPath: 'connections',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeConnectionImports;
|
||||
|
@ -28,10 +28,7 @@ export default {
|
||||
|
||||
async function writeIconImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/icons.js',
|
||||
content: templateFn({ packages: components.icons }),
|
||||
});
|
||||
await context.writeBuildArtifact('plugins/icons.js', templateFn({ packages: components.icons }));
|
||||
}
|
||||
|
||||
export default writeIconImports;
|
||||
|
@ -18,20 +18,20 @@ import generateImportFile from './generateImportFile.js';
|
||||
|
||||
async function writeOperatorImports({ components, context }) {
|
||||
// TODO: import _not and _type for validation.
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/operatorsClient.js',
|
||||
content: generateImportFile({
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/operatorsClient.js',
|
||||
generateImportFile({
|
||||
types: components.types.operators.client,
|
||||
importPath: 'operators/client',
|
||||
}),
|
||||
});
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/operatorsServer.js',
|
||||
content: generateImportFile({
|
||||
})
|
||||
);
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/operatorsServer.js',
|
||||
generateImportFile({
|
||||
types: components.types.operators.server,
|
||||
importPath: 'operators/server',
|
||||
}),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default writeOperatorImports;
|
||||
|
@ -24,10 +24,10 @@ const template = `@import '@lowdefy/layout/style.less';
|
||||
|
||||
async function writeStyleImports({ components, context }) {
|
||||
const templateFn = nunjucksFunction(template);
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'plugins/styles.less',
|
||||
content: templateFn({ styles: components.styles }),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
'plugins/styles.less',
|
||||
templateFn({ styles: components.styles })
|
||||
);
|
||||
}
|
||||
|
||||
export default writeStyleImports;
|
||||
|
@ -19,10 +19,10 @@ import { type } from '@lowdefy/helpers';
|
||||
async function writeRequestsOnPage({ page, context }) {
|
||||
return Promise.all(
|
||||
page.requests.map(async (request) => {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: `pages/${page.pageId}/requests/${request.requestId}.json`,
|
||||
content: JSON.stringify(request, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact(
|
||||
`pages/${page.pageId}/requests/${request.requestId}.json`,
|
||||
JSON.stringify(request, null, 2)
|
||||
);
|
||||
delete request.properties;
|
||||
delete request.type;
|
||||
delete request.connectionId;
|
||||
|
@ -49,9 +49,8 @@ test('writeRequests write request', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -65,7 +64,6 @@ test('writeRequests write request', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -104,9 +102,8 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -120,12 +117,10 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request2.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request2.json',
|
||||
`{
|
||||
"id": "request:page1:request2",
|
||||
"requestId": "request2",
|
||||
"pageId": "page1",
|
||||
@ -139,7 +134,6 @@ test('writeRequests write multiple requests on a page', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
@ -184,9 +178,8 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
await writeRequests({ components, context });
|
||||
expect(mockWriteBuildArtifact.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page1/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page1/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page1:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page1",
|
||||
@ -200,12 +193,10 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
filePath: 'pages/page2/requests/request1.json',
|
||||
content: `{
|
||||
'pages/page2/requests/request1.json',
|
||||
`{
|
||||
"id": "request:page2:request1",
|
||||
"requestId": "request1",
|
||||
"pageId": "page2",
|
||||
@ -219,7 +210,6 @@ test('writeRequests write requests on a for multiple pages', async () => {
|
||||
"key": "value"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
@ -15,10 +15,7 @@
|
||||
*/
|
||||
|
||||
async function writeTypes({ components, context }) {
|
||||
await context.writeBuildArtifact({
|
||||
filePath: 'types.json',
|
||||
content: JSON.stringify(components.types, null, 2),
|
||||
});
|
||||
await context.writeBuildArtifact('types.json', JSON.stringify(components.types, null, 2));
|
||||
}
|
||||
|
||||
export default writeTypes;
|
||||
|
@ -19,8 +19,8 @@
|
||||
import { readFile } from '@lowdefy/node-utils';
|
||||
|
||||
import createCounter from './utils/createCounter.js';
|
||||
import createReadConfigFile from './utils/files/readConfigFile.js';
|
||||
import createWriteBuildArtifact from './utils/files/writeBuildArtifact.js';
|
||||
import createReadConfigFile from './utils/readConfigFile.js';
|
||||
import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
|
||||
|
||||
import addDefaultPages from './build/addDefaultPages/addDefaultPages.js';
|
||||
import buildAuth from './build/buildAuth/buildAuth.js';
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import createWriteBuildArtifact from './writeBuildArtifact.js';
|
||||
|
||||
const directories = { build: path.resolve(process.cwd(), 'src/test/fileSetter') };
|
||||
|
||||
test('writeFile', async () => {
|
||||
const filePath = path.resolve(directories.build, 'writeFile.txt');
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (error) {
|
||||
//pass
|
||||
}
|
||||
expect(fs.existsSync(filePath)).toBe(false);
|
||||
const writeBuildArtifact = createWriteBuildArtifact({ directories });
|
||||
|
||||
await writeBuildArtifact({
|
||||
filePath: 'writeFile.txt',
|
||||
content: 'Test fileSetter file',
|
||||
});
|
||||
const res = fs.readFileSync(filePath, 'utf8');
|
||||
expect(res).toEqual('Test fileSetter file');
|
||||
try {
|
||||
fs.unlinkSync(filePath);
|
||||
} catch (error) {
|
||||
//pass
|
||||
}
|
||||
});
|
@ -18,8 +18,8 @@ import path from 'path';
|
||||
import { writeFile } from '@lowdefy/node-utils';
|
||||
|
||||
function createWriteBuildArtifact({ directories }) {
|
||||
async function writeBuildArtifact({ filePath, content }) {
|
||||
return writeFile(path.resolve(directories.build, filePath), content);
|
||||
async function writeBuildArtifact(filePath, content) {
|
||||
await writeFile(path.join(directories.build, filePath), content);
|
||||
}
|
||||
return writeBuildArtifact;
|
||||
}
|
33
packages/build/src/utils/writeBuildArtifact.test.js
Normal file
33
packages/build/src/utils/writeBuildArtifact.test.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
jest.mock('@lowdefy/node-utils', () => {
|
||||
return {
|
||||
writeFile: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const directories = { build: '/build' };
|
||||
|
||||
test('Write build artifact.', async () => {
|
||||
const nodeUtils = await import('@lowdefy/node-utils');
|
||||
nodeUtils.readFile.mockImplementation(() => Promise.resolve(null));
|
||||
const createWriteBuildArtifact = (await import('./writeBuildArtifact.js')).default;
|
||||
|
||||
const writeBuildArtifact = createWriteBuildArtifact({ directories });
|
||||
|
||||
await writeBuildArtifact('artifact.txt', 'Test artifact content');
|
||||
expect(nodeUtils.writeFile.mock.calls).toEqual([
|
||||
['/build/artifact.txt', 'Test artifact content'],
|
||||
]);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user