Skip to content

Commit d00e54a

Browse files
committed
eschew global.baseUrl to instead use project on emitter
1 parent e4f4945 commit d00e54a

File tree

9 files changed

+119
-90
lines changed

9 files changed

+119
-90
lines changed

packages/code-export-csharp-commons/src/command.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { codeExport as exporter, PrebuildEmitter } from 'side-code-export'
19-
import { ExportFlexCommandShape, ProcessedCommandEmitter } from 'side-code-export/dist/code-export/emit'
20-
import { ScriptShape } from 'side-code-export/src/code-export/preprocessor'
18+
import {
19+
codeExport as exporter,
20+
PrebuildEmitter,
21+
ExportFlexCommandShape,
22+
ProcessedCommandEmitter,
23+
EmitterContext,
24+
ScriptShape,
25+
} from 'side-code-export'
26+
// eslint-disable-next-line node/no-unpublished-import
2127
import { CommandShape } from '@seleniumhq/side-model'
2228
import location from './location'
2329
import selection from './selection'
@@ -130,10 +136,11 @@ function register(command: string, emitter: PrebuildEmitter) {
130136
exporter.register.emitter({ command, emitter, emitters })
131137
}
132138

133-
function emit(command: CommandShape) {
139+
function emit(command: CommandShape, context: EmitterContext) {
134140
return exporter.emit.command(command, emitters[command.command], {
135-
variableLookup,
141+
context,
136142
emitNewWindowHandling,
143+
variableLookup,
137144
})
138145
}
139146

@@ -302,7 +309,10 @@ function emitControlFlowIf(script: any) {
302309
})
303310
}
304311

305-
function emitControlFlowForEach(collectionVarName: string, iteratorVarName: string) {
312+
function emitControlFlowForEach(
313+
collectionVarName: string,
314+
iteratorVarName: string
315+
) {
306316
return Promise.resolve({
307317
commands: [
308318
{
@@ -500,12 +510,11 @@ async function emitMouseUp(locator: any) {
500510
return Promise.resolve({ commands })
501511
}
502512

503-
function emitOpen(target: string) {
513+
function emitOpen(target: string, _value: string, context: EmitterContext) {
504514
const url = /^(file|http|https):\/\//.test(target)
505-
? `"${target}"`
506-
: // @ts-expect-error globals yuck
507-
`"${global.baseUrl}${target}"`
508-
return Promise.resolve(`driver.Navigate().GoToUrl(${url});`)
515+
? target
516+
: `${context.project.url}${target}`
517+
return Promise.resolve(`driver.Navigate().GoToUrl("${url}");`)
509518
}
510519

511520
async function emitPause(time: any) {

packages/code-export-csharp-xunit/src/command.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
// under the License.
1717

1818
import { Command, location } from '@seleniumhq/code-export-csharp-commons'
19-
import { codeExport as exporter } from 'side-code-export'
19+
import { EmitterContext, codeExport as exporter } from 'side-code-export'
20+
// eslint-disable-next-line node/no-unpublished-import
2021
import { CommandShape } from '@seleniumhq/side-model'
2122

2223
const emitters = { ...Command.emitters }
2324

2425
exporter.register.preprocessors(emitters)
2526

26-
function emit(command: CommandShape) {
27+
function emit(command: CommandShape, context: EmitterContext) {
2728
return exporter.emit.command(command, emitters[command.command], {
28-
variableLookup: Command.variableLookup,
29+
context,
2930
emitNewWindowHandling: Command.extras.emitNewWindowHandling,
31+
variableLookup: Command.variableLookup,
3032
})
3133
}
3234

@@ -154,7 +156,10 @@ async function emitVerifyNotEditable(locator: string) {
154156
emitters.assertNotSelectedValue = emitVerifyNotSelectedValue
155157
emitters.verifyNotSelectedValue = emitVerifyNotSelectedValue
156158

157-
async function emitVerifyNotSelectedValue(locator: string, expectedValue: string) {
159+
async function emitVerifyNotSelectedValue(
160+
locator: string,
161+
expectedValue: string
162+
) {
158163
const commands = [
159164
{ level: 0, statement: '{' },
160165
{

packages/code-export-java-junit/src/command.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
// eslint-disable-next-line node/no-unpublished-import
1819
import { CommandShape } from '@seleniumhq/side-model'
1920
import {
21+
EmitterContext,
2022
codeExport as exporter,
2123
ExportFlexCommandShape,
2224
PrebuildEmitter,
@@ -134,8 +136,9 @@ function register(command: string, emitter: PrebuildEmitter) {
134136
exporter.register.emitter({ command, emitter, emitters })
135137
}
136138

137-
function emit(command: CommandShape) {
139+
function emit(command: CommandShape, context: EmitterContext) {
138140
return exporter.emit.command(command, emitters[command.command], {
141+
context,
139142
variableLookup,
140143
emitNewWindowHandling,
141144
})
@@ -496,11 +499,10 @@ async function emitMouseUp(locator: string) {
496499
return Promise.resolve({ commands })
497500
}
498501

499-
function emitOpen(target: string) {
502+
function emitOpen(target: string, _value: null, context: EmitterContext) {
500503
const url = /^(file|http|https):\/\//.test(target)
501504
? `"${target}"`
502-
: // @ts-expect-error globals yuck
503-
`"${global.baseUrl}${target}"`
505+
: `"${context.project.url}${target}"`
504506
return Promise.resolve(`driver.get(${url});`)
505507
}
506508

packages/code-export-javascript-mocha/src/command.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
// under the License.
1717

1818
import {
19+
EmitterContext,
1920
codeExport as exporter,
2021
ExportFlexCommandShape,
2122
PrebuildEmitter,
2223
ProcessedCommandEmitter,
2324
ScriptShape,
2425
} from 'side-code-export'
26+
// eslint-disable-next-line node/no-unpublished-import
2527
import { CommandShape } from '@seleniumhq/side-model'
2628
import location from './location'
2729
import selection from './selection'
@@ -134,8 +136,9 @@ function register(command: string, emitter: PrebuildEmitter) {
134136
exporter.register.emitter({ command, emitter, emitters })
135137
}
136138

137-
function emit(command: CommandShape) {
139+
function emit(command: CommandShape, context: EmitterContext) {
138140
return exporter.emit.command(command, emitters[command.command], {
141+
context,
139142
variableLookup,
140143
emitNewWindowHandling,
141144
})
@@ -182,7 +185,10 @@ function emitWaitForWindow() {
182185
})
183186
}
184187

185-
async function emitNewWindowHandling(command: CommandShape, emittedCommand: ExportFlexCommandShape) {
188+
async function emitNewWindowHandling(
189+
command: CommandShape,
190+
emittedCommand: ExportFlexCommandShape
191+
) {
186192
return Promise.resolve(
187193
`vars["windowHandles"] = await driver.getAllWindowHandles()\n${await emittedCommand}\nvars["${
188194
command.windowHandleName
@@ -309,7 +315,10 @@ function emitControlFlowIf(script: ScriptShape) {
309315
})
310316
}
311317

312-
function emitControlFlowForEach(collectionVarName: string, iteratorVarName: string) {
318+
function emitControlFlowForEach(
319+
collectionVarName: string,
320+
iteratorVarName: string
321+
) {
313322
return Promise.resolve({
314323
commands: [
315324
{
@@ -519,12 +528,11 @@ async function emitMouseUp(locator: string) {
519528
return Promise.resolve({ commands })
520529
}
521530

522-
function emitOpen(target: string) {
531+
function emitOpen(target: string, _value: unknown, context: EmitterContext) {
523532
const url = /^(file|http|https):\/\//.test(target)
524-
? `"${target}"`
525-
: // @ts-expect-error globals yuck
526-
`"${global.baseUrl}${target}"`
527-
return Promise.resolve(`await driver.get(${url})`)
533+
? target
534+
: `${context.project.url}${target}`
535+
return Promise.resolve(`await driver.get("${url}")`)
528536
}
529537

530538
async function emitPause(time: string) {
@@ -837,7 +845,10 @@ async function emitVerifyNotEditable(locator: string) {
837845
return Promise.resolve({ commands })
838846
}
839847

840-
async function emitVerifyNotSelectedValue(locator: string, expectedValue: string) {
848+
async function emitVerifyNotSelectedValue(
849+
locator: string,
850+
expectedValue: string
851+
) {
841852
const commands = [
842853
{ level: 0, statement: `{` },
843854
{
@@ -848,7 +859,7 @@ async function emitVerifyNotSelectedValue(locator: string, expectedValue: string
848859
},
849860
{
850861
level: 1,
851-
statement: `assert.equal(value, "${exporter.emit.text(expectedValue)}")`
862+
statement: `assert.equal(value, "${exporter.emit.text(expectedValue)}")`,
852863
},
853864
{ level: 0, statement: `}` },
854865
]
@@ -864,7 +875,10 @@ async function emitVerifyNotText(locator: string, text: string) {
864875
locator
865876
)}).getText()`,
866877
},
867-
{ level: 1, statement: `assert.notEqual(text, "${exporter.emit.text(text)}")` },
878+
{
879+
level: 1,
880+
statement: `assert.notEqual(text, "${exporter.emit.text(text)}")`,
881+
},
868882
{ level: 0, statement: `}` },
869883
]
870884
return Promise.resolve({ commands })

packages/code-export-python-pytest/src/command.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
// under the License.
1717

1818
import {
19+
EmitterContext,
1920
codeExport as exporter,
2021
ExportFlexCommandShape,
2122
PrebuildEmitter,
2223
ProcessedCommandEmitter,
2324
ScriptShape,
2425
} from 'side-code-export'
26+
// eslint-disable-next-line node/no-unpublished-import
2527
import { CommandShape } from '@seleniumhq/side-model'
2628
import location from './location'
2729
import selection from './selection'
@@ -134,8 +136,9 @@ function register(command: string, emitter: PrebuildEmitter) {
134136
exporter.register.emitter({ command, emitter, emitters })
135137
}
136138

137-
function emit(command: CommandShape) {
139+
function emit(command: CommandShape, context: EmitterContext) {
138140
return exporter.emit.command(command, emitters[command.command], {
141+
context,
139142
variableLookup,
140143
emitNewWindowHandling,
141144
})
@@ -499,12 +502,11 @@ async function emitMouseUp(locator: string) {
499502
return Promise.resolve({ commands })
500503
}
501504

502-
function emitOpen(target: string) {
505+
function emitOpen(target: string, _value: string, context: EmitterContext) {
503506
const url = /^(file|http|https):\/\//.test(target)
504-
? `"${target}"`
505-
: // @ts-expect-error globals yuck
506-
`"${global.baseUrl}${target}"`
507-
return Promise.resolve(`self.driver.get(${url})`)
507+
? target
508+
: `${context.project.url}${target}`
509+
return Promise.resolve(`self.driver.get("${url}")`)
508510
}
509511

510512
async function emitPause(time: number) {

packages/code-export-ruby-rspec/src/command.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
// under the License.
1717

1818
import {
19+
EmitterContext,
1920
codeExport as exporter,
2021
ExportFlexCommandShape,
2122
ProcessedCommandEmitter,
2223
ScriptShape,
2324
} from 'side-code-export'
25+
// eslint-disable-next-line node/no-unpublished-import
2426
import { CommandShape } from '@seleniumhq/side-model'
2527
import location from './location'
2628
import selection from './selection'
@@ -133,8 +135,9 @@ function register(command: string, emitter: ProcessedCommandEmitter) {
133135
exporter.register.emitter({ command, emitter, emitters })
134136
}
135137

136-
function emit(command: CommandShape) {
138+
function emit(command: CommandShape, context: EmitterContext) {
137139
return exporter.emit.command(command, emitters[command.command], {
140+
context,
138141
variableLookup,
139142
emitNewWindowHandling,
140143
})
@@ -479,11 +482,10 @@ async function emitMouseUp(locator: string) {
479482
return Promise.resolve({ commands })
480483
}
481484

482-
function emitOpen(target: string) {
485+
function emitOpen(target: string, _value: string, context: EmitterContext) {
483486
const url = /^(file|http|https):\/\//.test(target)
484487
? `'${target}'`
485-
: // @ts-expect-error globals yuck
486-
`"${global.baseUrl}${target}"`
488+
: `"${context.project.url}${target}"`
487489
return Promise.resolve(`@driver.get(${url})`)
488490
}
489491

@@ -767,7 +769,10 @@ async function emitVerifyNotEditable(locator: string) {
767769
return Promise.resolve({ commands })
768770
}
769771

770-
async function emitVerifyNotSelectedValue(locator: string, expectedValue: string) {
772+
async function emitVerifyNotSelectedValue(
773+
locator: string,
774+
expectedValue: string
775+
) {
771776
const commands = [
772777
{
773778
level: 0,

packages/side-code-export/src/code-export/defaults.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export const languageFromOpts = (
1414
beforeEachOptions,
1515
enableDescriptionAsComment,
1616
}) {
17-
// @ts-expect-error globals yuck
18-
global.baseUrl = baseUrl
1917
const testDeclaration = opts.generateTestDeclaration(test.name)
2018
const result = await emit.test(test, tests, {
2119
...opts,

0 commit comments

Comments
 (0)