From 42603bc2483adb418ee0514808d9b02320fad2cb Mon Sep 17 00:00:00 2001 From: Marko Mackic Date: Wed, 4 Mar 2020 11:07:22 +0100 Subject: [PATCH 1/2] Package for java exports. --- packages/code-export-java-junit/src/hook.js | 21 ++++++--- packages/code-export-java-junit/src/index.js | 8 ++++ packages/selenium-ide/package.json | 1 + .../neo/components/Dialogs/Export/index.jsx | 45 +++++++++++++++++++ packages/selenium-ide/src/neo/models/Suite.js | 4 ++ .../selenium-ide/src/neo/models/TestCase.js | 5 ++- yarn.lock | 2 +- 7 files changed, 79 insertions(+), 7 deletions(-) diff --git a/packages/code-export-java-junit/src/hook.js b/packages/code-export-java-junit/src/hook.js index e5471ae5e..42862ac80 100644 --- a/packages/code-export-java-junit/src/hook.js +++ b/packages/code-export-java-junit/src/hook.js @@ -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 } @@ -119,7 +119,7 @@ function beforeEach() { return params } -function declareDependencies() { +function declareDependencies(exportObject) { const params = { startingSyntax: { commands: [ @@ -174,6 +174,17 @@ function declareDependencies() { ], }, } + + if(exportObject && exportObject.additionalOpts && exportObject.additionalOpts.package) + { + params.startingSyntax.commands.unshift( + { + level : 0, + statement : `package ${exportObject.additionalOpts.package};` + } + ) + } + return params } diff --git a/packages/code-export-java-junit/src/index.js b/packages/code-export-java-junit/src/index.js index 8a1023776..2ca230f60 100644 --- a/packages/code-export-java-junit/src/index.js +++ b/packages/code-export-java-junit/src/index.js @@ -62,6 +62,10 @@ 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, { @@ -96,6 +100,10 @@ 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, diff --git a/packages/selenium-ide/package.json b/packages/selenium-ide/package.json index 2b6b7dff0..b0b48dc9f 100644 --- a/packages/selenium-ide/package.json +++ b/packages/selenium-ide/package.json @@ -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", diff --git a/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx b/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx index 09616ce28..d6da04b69 100644 --- a/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx +++ b/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx @@ -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' @@ -49,12 +50,25 @@ export default class ExportDialog extends React.Component { class ExportContent extends React.Component { 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, @@ -80,6 +94,21 @@ 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 ( l.toLowerCase().includes("java")) ? ( + { + this.onExportPackageChange(value) + }} + /> + ) : ( + undefined + )} + + ) } diff --git a/packages/selenium-ide/src/neo/models/Suite.js b/packages/selenium-ide/src/neo/models/Suite.js index 8b6cde859..dbd5daae3 100644 --- a/packages/selenium-ide/src/neo/models/Suite.js +++ b/packages/selenium-ide/src/neo/models/Suite.js @@ -38,6 +38,8 @@ export default class Suite { modified = false @observable isOpen = false + @observable + additionalOpts = {} constructor(id = uuidv4(), name = 'Untitled Suite') { this.id = id @@ -170,6 +172,7 @@ export default class Suite { parallel: this.isParallel, timeout: this.timeout, tests: this._tests.map(t => t.id), + additionalOpts: this.additionalOpts } } @@ -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 } diff --git a/packages/selenium-ide/src/neo/models/TestCase.js b/packages/selenium-ide/src/neo/models/TestCase.js index 06e599728..f2f21d77a 100644 --- a/packages/selenium-ide/src/neo/models/TestCase.js +++ b/packages/selenium-ide/src/neo/models/TestCase.js @@ -32,6 +32,8 @@ export default class TestCase { selectedCommand = null @observable scrollY = null + @observable + additionalOpts = {} constructor(id = uuidv4(), name = 'Untitled Test') { this.id = id @@ -155,6 +157,7 @@ export default class TestCase { id: this.id, name: this.name, commands: this.commands.map(c => c.export()), + additionalOpts: this.additionalOpts } } @@ -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 } } diff --git a/yarn.lock b/yarn.lock index d80e064c0..f149bc4f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== From 2a3754cba4d8c6f6fd3fe75c095efe16d50c0078 Mon Sep 17 00:00:00 2001 From: Marko Mackic Date: Wed, 4 Mar 2020 11:26:25 +0100 Subject: [PATCH 2/2] eslint fix --- packages/code-export-java-junit/src/hook.js | 17 +++++----- packages/code-export-java-junit/src/index.js | 6 ++-- .../neo/components/Dialogs/Export/index.jsx | 31 +++++++++---------- packages/selenium-ide/src/neo/models/Suite.js | 4 +-- .../selenium-ide/src/neo/models/TestCase.js | 4 +-- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/packages/code-export-java-junit/src/hook.js b/packages/code-export-java-junit/src/hook.js index 42862ac80..b192a087f 100644 --- a/packages/code-export-java-junit/src/hook.js +++ b/packages/code-export-java-junit/src/hook.js @@ -175,14 +175,15 @@ function declareDependencies(exportObject) { }, } - if(exportObject && exportObject.additionalOpts && exportObject.additionalOpts.package) - { - params.startingSyntax.commands.unshift( - { - level : 0, - statement : `package ${exportObject.additionalOpts.package};` - } - ) + if ( + exportObject && + exportObject.additionalOpts && + exportObject.additionalOpts.package + ) { + params.startingSyntax.commands.unshift({ + level: 0, + statement: `package ${exportObject.additionalOpts.package};`, + }) } return params diff --git a/packages/code-export-java-junit/src/index.js b/packages/code-export-java-junit/src/index.js index 2ca230f60..0dc16e5f5 100644 --- a/packages/code-export-java-junit/src/index.js +++ b/packages/code-export-java-junit/src/index.js @@ -62,9 +62,8 @@ export async function emitTest({ beforeEachOptions, enableDescriptionAsComment, }) { - // regenerate hooks with exported object - opts.hooks = generateHooks(test); + opts.hooks = generateHooks(test) global.baseUrl = baseUrl const testDeclaration = generateTestDeclaration(test.name) @@ -100,9 +99,8 @@ export async function emitSuite({ beforeEachOptions, enableDescriptionAsComment, }) { - // regenerate hooks with exported object; - opts.hooks = generateHooks(suite); + opts.hooks = generateHooks(suite) global.baseUrl = baseUrl const result = await exporter.emit.testsFromSuite(tests, suite, opts, { diff --git a/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx b/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx index d6da04b69..ec222aa70 100644 --- a/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx +++ b/packages/selenium-ide/src/neo/components/Dialogs/Export/index.jsx @@ -17,7 +17,7 @@ import React from 'react' import PropTypes from 'prop-types' -import {get} from 'lodash' +import { get } from 'lodash' import Modal from '../../Modal' import DialogContainer from '../Dialog' import FlatButton from '../../FlatButton' @@ -51,7 +51,7 @@ class ExportContent extends React.Component { constructor(props) { super(props) - this.DEF_PACKAGE = ""; + this.DEF_PACKAGE = '' this.state = { selectedLanguages: [UiState.selectedExportLanguage], @@ -68,7 +68,7 @@ class ExportContent extends React.Component { this.DEF_PACKAGE, } - this.onExportPackageChange(this.state.package); + this.onExportPackageChange(this.state.package) } static propTypes = { cancelSelection: PropTypes.func.isRequired, @@ -94,19 +94,16 @@ 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 = {}; + onExportPackageChange(input) { + if (ModalState.exportPayload) { + Object.values(ModalState.exportPayload).forEach(function(e) { + if (!e.additionalOpts) e.additionalOpts = {} - e.additionalOpts.package = input - }) - } + e.additionalOpts.package = input + }) + } - this.setState({ package: input}); + this.setState({ package: input }) } render() { @@ -187,7 +184,9 @@ class ExportContent extends React.Component { undefined )} - {this.state.selectedLanguages.every(l => l.toLowerCase().includes("java")) ? ( + {this.state.selectedLanguages.every(l => + l.toLowerCase().includes('java') + ) ? ( ) } diff --git a/packages/selenium-ide/src/neo/models/Suite.js b/packages/selenium-ide/src/neo/models/Suite.js index dbd5daae3..a7a7e155b 100644 --- a/packages/selenium-ide/src/neo/models/Suite.js +++ b/packages/selenium-ide/src/neo/models/Suite.js @@ -172,7 +172,7 @@ export default class Suite { parallel: this.isParallel, timeout: this.timeout, tests: this._tests.map(t => t.id), - additionalOpts: this.additionalOpts + additionalOpts: this.additionalOpts, } } @@ -186,7 +186,7 @@ export default class Suite { suite._tests.replace( jsRep.tests.map(testId => projectTests.find(({ id }) => id === testId)) ) - suite.additionalOpts = jsRep.additionalOpts || {}; + suite.additionalOpts = jsRep.additionalOpts || {} return suite } diff --git a/packages/selenium-ide/src/neo/models/TestCase.js b/packages/selenium-ide/src/neo/models/TestCase.js index f2f21d77a..60eaca9a7 100644 --- a/packages/selenium-ide/src/neo/models/TestCase.js +++ b/packages/selenium-ide/src/neo/models/TestCase.js @@ -157,7 +157,7 @@ export default class TestCase { id: this.id, name: this.name, commands: this.commands.map(c => c.export()), - additionalOpts: this.additionalOpts + additionalOpts: this.additionalOpts, } } @@ -170,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; + test.additionalOpts = jsRep.additionalOpts return test } }