Skip to content

Commit 30d9161

Browse files
author
David Haeffner
committed
In code export -- added recursive lookup of reused test cases for commands that open a new window, so the new window util method is emitted.
1 parent e648a0f commit 30d9161

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

packages/code-export-utils/__test__/src/find.spec.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,28 @@ describe('find', () => {
3030
const command = new Command(undefined, 'click', 'id=blah')
3131
command.opensWindow = true
3232
test.addCommand(command)
33-
const result = findCommandThatOpensWindow(test.commands)
33+
const result = findCommandThatOpensWindow(test)
3434
expect(result.command).toEqual('click')
3535
})
3636
it('should not find a command that opens a window if one is not present in a test', () => {
3737
const test = new TestCase(undefined, 'blah')
3838
test.createCommand(undefined, 'open', '/')
3939
const command = new Command(undefined, 'click', 'id=blah')
4040
test.addCommand(command)
41-
const result = findCommandThatOpensWindow(test.commands)
41+
const result = findCommandThatOpensWindow(test)
4242
expect(result).toBeUndefined()
4343
})
44+
it('should find a command within a reused test method', () => {
45+
const test = new TestCase()
46+
test.createCommand(undefined, 'run', 'blah')
47+
const anotherTest = new TestCase(undefined, 'blah')
48+
const command = new Command(undefined, 'click', 'id=blah')
49+
command.opensWindow = true
50+
anotherTest.addCommand(command)
51+
const tests = [test, anotherTest]
52+
const result = findCommandThatOpensWindow(test, tests)
53+
expect(result).toBeTruthy()
54+
})
4455
})
4556
describe('findReusedTestMethods', () => {
4657
it('should find a reused test method', () => {

packages/code-export-utils/src/emit.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ async function emitTest(
148148
if (!commandLevel) commandLevel = 2
149149
const methods = findReusedTestMethods(test, tests)
150150
if (emitter.extras) {
151-
Object.keys(emitter.extras).forEach(async emitter_name => {
151+
for (const emitter_name in emitter.extras) {
152152
let ignore = true
153153
if (
154154
emitter_name === 'emitWaitForWindow' &&
155-
findCommandThatOpensWindow(test.commands)
155+
findCommandThatOpensWindow(test, tests)
156156
)
157157
ignore = false
158158
if (!ignore) {
@@ -169,7 +169,7 @@ async function emitTest(
169169
hooks,
170170
})
171171
}
172-
})
172+
}
173173
}
174174
for (const method of methods) {
175175
const result = await emitMethod(method, {

packages/code-export-utils/src/find.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ export function findReusedTestMethods(test, tests, _results) {
2727
return results
2828
}
2929

30-
export function findCommandThatOpensWindow(commands) {
30+
export function findCommandThatOpensWindow(test, tests) {
3131
let result
32-
for (const command of commands) {
32+
for (const command of test.commands) {
3333
if (command.opensWindow) {
3434
result = command
3535
break
3636
}
37+
if (command.command === 'run') {
38+
const nestedTests = findReusedTestMethods(test, tests)
39+
for (const nestedTest in nestedTests) {
40+
return findCommandThatOpensWindow(nestedTests[nestedTest], nestedTests)
41+
}
42+
}
3743
}
3844
return result
3945
}

0 commit comments

Comments
 (0)