diff --git a/e2e/e2e.js b/e2e/e2e.js index 94e56c4..581a8b3 100644 --- a/e2e/e2e.js +++ b/e2e/e2e.js @@ -67,22 +67,6 @@ test('HTTPS_PROXY must be set if E2E_USE_PROXY is set', () => { } }) -describe('build-actions', () => { - test('full config', async () => { - /* skip checking previously built actions */ - utils.dumpActionsBuiltInfo = jest.fn(() => false) - utils.actionBuiltBefore = jest.fn(() => false) - - expect(await sdk.buildActions(config)).toEqual(expect.arrayContaining([ - expect.stringContaining('action.zip'), - expect.stringContaining('action-zip.zip') - ])) - expect(fs.readdirSync(path.resolve(config.actions.dist, 'sample-app-1.0.0'))).toEqual(expect.arrayContaining(['action-temp', 'action-zip-temp', 'action-zip.zip', 'action.zip'])) - fs.emptydirSync(config.actions.dist) - fs.rmdirSync(config.actions.dist) - }) -}) - describe('build, deploy, invoke and undeploy of actions', () => { test('basic manifest', async () => { /* skip checking previously built actions */ diff --git a/test/build.actions.test.js b/test/build.actions.test.js index b044fc6..f4fa966 100644 --- a/test/build.actions.test.js +++ b/test/build.actions.test.js @@ -12,6 +12,7 @@ governing permissions and limitations under the License. const utils = require('../src/utils') const buildActions = require('../src/build-actions') const path = require('path') +const fs = require('fs-extra') const execa = require('execa') jest.mock('execa') @@ -56,18 +57,29 @@ beforeEach(() => { describe('build by zipping js action folder', () => { let config - beforeEach(async () => { - global.fakeFileSystem.addJson({ + + /** @private */ + function setupFs ({ addActionFile = false }) { + const json = { 'actions/action-zip/index.js': global.fixtureFile('/sample-app/actions/action-zip/index.js'), 'actions/action-zip/package.json': global.fixtureFile('/sample-app/actions/action-zip/package.json'), - // 'actions/action.js': global.fixtureFile('/sample-app/actions/action.js'), 'web-src/index.html': global.fixtureFile('/sample-app/web-src/index.html'), 'manifest.yml': global.fixtureFile('/sample-app/manifest.yml'), 'package.json': global.fixtureFile('/sample-app/package.json') - }) + } + if (addActionFile) { + json['actions/action.js'] = global.fixtureFile('/sample-app/actions/action.js') + } + global.fakeFileSystem.addJson(json) + config = deepClone(global.sampleAppConfig) - // delete config.manifest.package.actions.action - delete config.manifest.full.packages.__APP_PACKAGE__.actions.action + if (!addActionFile) { + delete config.manifest.full.packages.__APP_PACKAGE__.actions.action + } + } + + beforeEach(async () => { + setupFs({ addActionFile: false }) }) afterEach(() => { @@ -170,6 +182,35 @@ describe('build by zipping js action folder', () => { expect(utils.zip).toHaveBeenCalledWith(path.normalize('/dist/actions/sample-app-1.0.0/action-zip-temp'), path.normalize('/dist/actions/sample-app-1.0.0/action-zip.zip')) }) + + test('full config', async () => { + setupFs({ addActionFile: true }) + + const lastBuiltActionsFile = path.join(config.root, 'dist', 'last-built-actions.json') + webpackMock.run.mockImplementation(cb => { + global.fakeFileSystem.addJson({ + [lastBuiltActionsFile]: '{}' + }) + cb(null, webpackStatsMock) + }) + + utils.zip.mockImplementation((_, outPath) => { + global.fakeFileSystem.addJson({ [outPath]: 'fake-zip-data' }) + }) + + const res = await buildActions(config) + expect(res).toEqual(expect.arrayContaining([ + expect.stringContaining('action.zip'), + expect.stringContaining('action-zip.zip') + ])) + + expect(fs.readdirSync(path.resolve(config.actions.dist, 'sample-app-1.0.0'))).toEqual(expect.arrayContaining([ + 'action-temp', + 'action-zip-temp', + 'action-zip.zip', + 'action.zip' + ])) + }) }) describe('build by bundling js action file with webpack', () => {