Skip to content

Commit efe9659

Browse files
authored
Consolidate duplicated code in one place (#2078)
1 parent 558c3d4 commit efe9659

31 files changed

+329
-1023
lines changed

dagger/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class VscodeRunme {
205205
baseOwner: string,
206206
eventName: string,
207207
forkOwner: string,
208-
specRetries: number = 5,
208+
specRetries: number = 3,
209209
): Promise<VscodeRunme> {
210210
await this.base()
211211

tests/e2e/helpers/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ async function assertDocumentContains(
9797
const matcherParts = sanitizeOutput(matcher).split('\n')
9898
const maxContentLines = Math.min(matcherParts.length, savedContent.length)
9999

100-
console.log('source:', source)
101-
console.log('savedContent', savedContent)
102-
console.log('matcherParts', matcherParts)
103-
console.log('maxContentLines', maxContentLines)
100+
// console.log('source:', source)
101+
// console.log('savedContent', savedContent)
102+
// console.log('matcherParts', matcherParts)
103+
// console.log('maxContentLines', maxContentLines)
104104

105105
for (let index = 0; index < maxContentLines; index++) {
106106
if (exact) {
@@ -172,9 +172,11 @@ export async function getRepoBasename(): Promise<string> {
172172
return path.basename(filePath.pathname)
173173
}
174174

175+
export type RunmeLifecycleIdentity = 'None' | 'Doc' | 'Cell' | 'All'
176+
175177
export async function switchLifecycleIdentity(
176178
workbench: Workbench,
177-
identity: 'None' | 'Doc' | 'Cell' | 'All',
179+
identity: RunmeLifecycleIdentity,
178180
) {
179181
// run three times to ensure it takes effect
180182
for (let i = 0; i < 3; i++) {
Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,9 @@
1-
import { Key } from 'webdriverio'
1+
import { runIdentityTests } from './identity.shared.js'
22

3-
import {
4-
assertDocumentContainsSpinner,
5-
revertChanges,
6-
saveFile,
7-
switchLifecycleIdentity,
8-
} from '../../helpers/index.js'
9-
import { removeAllNotifications } from '../notifications.js'
10-
11-
describe('Test suite: Empty file with setting All (1)', async () => {
12-
before(async () => {
13-
await removeAllNotifications()
14-
})
15-
16-
it('open identity markdown file', async () => {
17-
const workbench = await browser.getWorkbench()
18-
await switchLifecycleIdentity(workbench, 'All')
19-
20-
await browser.executeWorkbench(async (vscode) => {
21-
const doc = await vscode.workspace.openTextDocument(
22-
vscode.Uri.file(`${vscode.workspace.rootPath}/tests/fixtures/identity/empty-file.md`),
23-
)
24-
return vscode.window.showNotebookDocument(doc, {
25-
viewColumn: vscode.ViewColumn.Active,
26-
})
27-
})
28-
})
29-
30-
it('selects Runme kernel', async () => {
31-
const workbench = await browser.getWorkbench()
32-
await workbench.executeCommand('Select Notebook Kernel')
33-
await browser.keys([Key.Enter])
34-
})
35-
36-
it('should not remove the front matter with the identity', async () => {
37-
const absDocPath = await browser.executeWorkbench(async (vscode, documentPath) => {
38-
return `${vscode.workspace.rootPath}${documentPath}`
39-
}, '/tests/fixtures/identity/empty-file.md')
40-
41-
await saveFile(browser)
42-
await assertDocumentContainsSpinner(absDocPath, '')
43-
})
44-
45-
after(async () => {
46-
//revert changes we made during the test
47-
await revertChanges('empty-file.md')
3+
describe('Test suite: Empty file with setting All (1)', () => {
4+
runIdentityTests({
5+
lifecycleSetting: 'All',
6+
fixtureFile: '/tests/fixtures/identity/empty-file.md',
7+
expectedOutput: '',
488
})
499
})
Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,9 @@
1-
import { Key } from 'webdriverio'
1+
import { runIdentityTests } from './identity.shared.js'
22

3-
import {
4-
assertDocumentContainsSpinner,
5-
revertChanges,
6-
saveFile,
7-
switchLifecycleIdentity,
8-
} from '../../helpers/index.js'
9-
import { removeAllNotifications } from '../notifications.js'
10-
11-
describe('Test suite: Empty file with setting Cell (3)', async () => {
12-
before(async () => {
13-
await removeAllNotifications()
14-
})
15-
it('open identity markdown file', async () => {
16-
const workbench = await browser.getWorkbench()
17-
await switchLifecycleIdentity(workbench, 'Cell')
18-
19-
await browser.executeWorkbench(async (vscode) => {
20-
const doc = await vscode.workspace.openTextDocument(
21-
vscode.Uri.file(`${vscode.workspace.rootPath}/tests/fixtures/identity/empty-file.md`),
22-
)
23-
return vscode.window.showNotebookDocument(doc, {
24-
viewColumn: vscode.ViewColumn.Active,
25-
})
26-
})
27-
})
28-
29-
it('selects Runme kernel', async () => {
30-
const workbench = await browser.getWorkbench()
31-
await workbench.executeCommand('Select Notebook Kernel')
32-
await browser.keys([Key.Enter])
33-
})
34-
35-
it('should not remove the front matter with the identity', async () => {
36-
const absDocPath = await browser.executeWorkbench(async (vscode, documentPath) => {
37-
return `${vscode.workspace.rootPath}${documentPath}`
38-
}, '/tests/fixtures/identity/empty-file.md')
39-
40-
await saveFile(browser)
41-
await assertDocumentContainsSpinner(absDocPath, '')
42-
})
43-
44-
after(async () => {
45-
//revert changes we made during the test
46-
await revertChanges('empty-file.md')
3+
describe('Test suite: Empty file with setting Cell only (3)', () => {
4+
runIdentityTests({
5+
lifecycleSetting: 'Cell',
6+
fixtureFile: '/tests/fixtures/identity/empty-file.md',
7+
expectedOutput: '',
478
})
489
})
Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,9 @@
1-
import { Key } from 'webdriverio'
1+
import { runIdentityTests } from './identity.shared.js'
22

3-
import {
4-
assertDocumentContainsSpinner,
5-
revertChanges,
6-
saveFile,
7-
switchLifecycleIdentity,
8-
} from '../../helpers/index.js'
9-
import { removeAllNotifications } from '../notifications.js'
10-
11-
describe('Test suite: Empty file with setting Document (2)', async () => {
12-
before(async () => {
13-
await removeAllNotifications()
14-
})
15-
16-
it('open identity markdown file', async () => {
17-
const workbench = await browser.getWorkbench()
18-
await switchLifecycleIdentity(workbench, 'Doc')
19-
20-
await browser.executeWorkbench(async (vscode) => {
21-
const doc = await vscode.workspace.openTextDocument(
22-
vscode.Uri.file(`${vscode.workspace.rootPath}/tests/fixtures/identity/empty-file.md`),
23-
)
24-
return vscode.window.showNotebookDocument(doc, {
25-
viewColumn: vscode.ViewColumn.Active,
26-
})
27-
})
28-
})
29-
30-
it('selects Runme kernel', async () => {
31-
const workbench = await browser.getWorkbench()
32-
await workbench.executeCommand('Select Notebook Kernel')
33-
await browser.keys([Key.Enter])
34-
})
35-
36-
it('should not remove the front matter with the identity', async () => {
37-
const absDocPath = await browser.executeWorkbench(async (vscode, documentPath) => {
38-
return `${vscode.workspace.rootPath}${documentPath}`
39-
}, '/tests/fixtures/identity/empty-file.md')
40-
41-
await saveFile(browser)
42-
await assertDocumentContainsSpinner(absDocPath, '')
43-
})
44-
45-
after(async () => {
46-
//revert changes we made during the test
47-
await revertChanges('empty-file.md')
3+
describe('Test suite: Empty file with setting Document (2)', () => {
4+
runIdentityTests({
5+
lifecycleSetting: 'Doc',
6+
fixtureFile: '/tests/fixtures/identity/empty-file.md',
7+
expectedOutput: '',
488
})
499
})
Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
import { Key } from 'webdriverio'
2-
3-
import {
4-
assertDocumentContainsSpinner,
5-
revertChanges,
6-
saveFile,
7-
switchLifecycleIdentity,
8-
} from '../../helpers/index.js'
9-
import { removeAllNotifications } from '../notifications.js'
10-
11-
describe('Test suite: Empty file with setting None (0)', async () => {
12-
before(async () => {
13-
await removeAllNotifications()
14-
})
15-
16-
it('open identity markdown file', async () => {
17-
const workbench = await browser.getWorkbench()
18-
await switchLifecycleIdentity(workbench, 'None')
19-
20-
await browser.executeWorkbench(async (vscode) => {
21-
const doc = await vscode.workspace.openTextDocument(
22-
vscode.Uri.file(`${vscode.workspace.rootPath}/tests/fixtures/identity/empty-file.md`),
23-
)
24-
return vscode.window.showNotebookDocument(doc, {
25-
viewColumn: vscode.ViewColumn.Active,
26-
})
27-
})
28-
})
29-
30-
it('selects Runme kernel', async () => {
31-
const workbench = await browser.getWorkbench()
32-
await workbench.executeCommand('Select Notebook Kernel')
33-
await browser.keys([Key.Enter])
34-
})
35-
36-
it('should not remove the front matter with the identity', async () => {
37-
const absDocPath = await browser.executeWorkbench(async (vscode, documentPath) => {
38-
return `${vscode.workspace.rootPath}${documentPath}`
39-
}, '/tests/fixtures/identity/empty-file.md')
40-
41-
await saveFile(browser)
42-
await assertDocumentContainsSpinner(absDocPath, '', true)
43-
})
44-
45-
after(async () => {
46-
//revert changes we made during the test
47-
await revertChanges('empty-file.md')
1+
import { runIdentityTests } from './identity.shared.js'
2+
3+
describe('Test suite: Empty file with setting None (0)', () => {
4+
runIdentityTests({
5+
lifecycleSetting: 'None',
6+
fixtureFile: '/tests/fixtures/identity/empty-file.md',
7+
expectedOutput: '',
8+
assertOptions: { strict: true },
489
})
4910
})

tests/e2e/specs/identity/identity.existent-cell.cell.e2e.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)