Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional package for Java exports. #978

Open
wants to merge 3 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/code-export-java-junit/src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const emitters = {
inEachEnd: empty,
}

function generate(hookName) {
return new exporter.hook(emitters[hookName]())
function generate(hookName, exportObject) {
return new exporter.hook(emitters[hookName](exportObject))
}

export function generateHooks() {
export function generateHooks(exportObject) {
let result = {}
Object.keys(emitters).forEach(hookName => {
result[hookName] = generate(hookName)
result[hookName] = generate(hookName, exportObject)
})
return result
}
Expand Down Expand Up @@ -119,7 +119,7 @@ function beforeEach() {
return params
}

function declareDependencies() {
function declareDependencies(exportObject) {
const params = {
startingSyntax: {
commands: [
Expand Down Expand Up @@ -174,6 +174,18 @@ function declareDependencies() {
],
},
}

if (
exportObject &&
exportObject.additionalOpts &&
exportObject.additionalOpts.package
) {
params.startingSyntax.commands.unshift({
level: 0,
statement: `package ${exportObject.additionalOpts.package};`,
})
}

return params
}

Expand Down
6 changes: 6 additions & 0 deletions packages/code-export-java-junit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export async function emitTest({
beforeEachOptions,
enableDescriptionAsComment,
}) {
// regenerate hooks with exported object
opts.hooks = generateHooks(test)

global.baseUrl = baseUrl
const testDeclaration = generateTestDeclaration(test.name)
const result = await exporter.emit.test(test, tests, {
Expand Down Expand Up @@ -96,6 +99,9 @@ export async function emitSuite({
beforeEachOptions,
enableDescriptionAsComment,
}) {
// regenerate hooks with exported object;
opts.hooks = generateHooks(suite)

global.baseUrl = baseUrl
const result = await exporter.emit.testsFromSuite(tests, suite, opts, {
enableOriginTracing,
Expand Down
1 change: 1 addition & 0 deletions packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"fuse.js": "^3.3.0",
"google-closure-library": "^20170521.0.0",
"js-beautify": "^1.7.5",
"lodash": "^4.17.15",
"mobx": "^5.9.0",
"mobx-react": "^5.4.3",
"modifier-keys": "^1.2.1",
Expand Down
42 changes: 42 additions & 0 deletions packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import React from 'react'
import PropTypes from 'prop-types'
import { get } from 'lodash'
import Modal from '../../Modal'
import DialogContainer from '../Dialog'
import FlatButton from '../../FlatButton'
Expand Down Expand Up @@ -53,12 +54,25 @@ class ExportContent extends React.Component {
static modalDescriptionElement = 'renameDescription'
constructor(props) {
super(props)

this.DEF_PACKAGE = ''

this.state = {
selectedLanguages: [UiState.selectedExportLanguage],
enableOriginTracing: false,
enableGridConfig: UiState.gridConfigEnabled,
gridConfigUrl: UiState.specifiedRemoteUrl,
package:
(ModalState.exportPayload &&
get(
Object.values(ModalState.exportPayload)[0],
'additionalOpts.package',
this.DEF_PACKAGE
)) ||
this.DEF_PACKAGE,
}

this.onExportPackageChange(this.state.package)
}
static propTypes = {
cancelSelection: PropTypes.func.isRequired,
Expand All @@ -84,6 +98,18 @@ class ExportContent extends React.Component {
UiState.specifyRemoteUrl(input)
this.setState({ gridConfigUrl: input })
}
onExportPackageChange(input) {
if (ModalState.exportPayload) {
Object.values(ModalState.exportPayload).forEach(function(e) {
if (!e.additionalOpts) e.additionalOpts = {}

e.additionalOpts.package = input
})
}

this.setState({ package: input })
}

render() {
return (
<DialogContainer
Expand Down Expand Up @@ -164,6 +190,22 @@ class ExportContent extends React.Component {
) : (
undefined
)}

{this.state.selectedLanguages.every(l =>
l.toLowerCase().includes('java')
) ? (
<Input
id="export-package"
name="export-package"
label="Export package"
value={this.state.package}
onChange={value => {
this.onExportPackageChange(value)
}}
/>
) : (
undefined
)}
</DialogContainer>
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/selenium-ide/src/neo/models/Suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class Suite {
modified = false
@observable
isOpen = false
@observable
additionalOpts = {}

constructor(id = uuidv4(), name = 'Untitled Suite') {
this.id = id
Expand Down Expand Up @@ -170,6 +172,7 @@ export default class Suite {
parallel: this.isParallel,
timeout: this.timeout,
tests: this._tests.map(t => t.id),
additionalOpts: this.additionalOpts,
}
}

Expand All @@ -183,6 +186,7 @@ export default class Suite {
suite._tests.replace(
jsRep.tests.map(testId => projectTests.find(({ id }) => id === testId))
)
suite.additionalOpts = jsRep.additionalOpts || {}

return suite
}
Expand Down
5 changes: 4 additions & 1 deletion packages/selenium-ide/src/neo/models/TestCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class TestCase {
selectedCommand = null
@observable
scrollY = null
@observable
additionalOpts = {}

constructor(id = uuidv4(), name = 'Untitled Test') {
this.id = id
Expand Down Expand Up @@ -155,6 +157,7 @@ export default class TestCase {
id: this.id,
name: this.name,
commands: this.commands.map(c => c.export()),
additionalOpts: this.additionalOpts,
}
}

Expand All @@ -167,7 +170,7 @@ export default class TestCase {
const test = new TestCase(jsRep.id)
test.setName(jsRep.name)
test.commands.replace(jsRep.commands.map(Command.fromJS))

test.additionalOpts = jsRep.additionalOpts
return test
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8054,7 +8054,7 @@ lodash@^4.17.10, lodash@^4.17.11:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.3, lodash@^4.2.0, lodash@^4.6.1:
lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.2.0, lodash@^4.6.1:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down