Skip to content

Commit

Permalink
fix: ACNA-2479 - e2e test should be a unit test (#161)
Browse files Browse the repository at this point in the history
closes #152
  • Loading branch information
shazron authored Aug 31, 2023
1 parent de08593 commit 26046f9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
16 changes: 0 additions & 16 deletions e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
53 changes: 47 additions & 6 deletions test/build.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 26046f9

Please sign in to comment.