Skip to content

Commit 32dce78

Browse files
committed
500+ tests zomg
1 parent d098179 commit 32dce78

File tree

109 files changed

+1926
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1926
-935
lines changed

.github/workflows/release-npm.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: pnpm -r i
4242
env:
4343
NODE_ENV: "production"
44-
- name: Publish non IDE packages to npm
45-
run: pnpm -r publish --no-git-checks --filter=!packages/selenium-ide --access public
44+
- name: Publish packages to npm
45+
run: pnpm -r publish --no-git-checks --access public
4646
env:
4747
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ jobs:
3333
run: pnpm -r i
3434
- name: Build side-runner and selenium-ide
3535
run: pnpm run build
36-
- name: Test the side-runner
36+
- name: Run the tests
37+
run: npm run test:setup
38+
- name: Run the project examples as tests
3739
run: npm run test:side-runner:ci

jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
tsConfig: 'tsconfig.base.json',
55
},
66
},
7+
projects: ['<rootDir>/packages/*/jest.config.js'],
78
testEnvironment: 'jsdom',
89
testEnvironmentOptions: {
910
url: 'http://localhost/index.html',
@@ -12,7 +13,7 @@ module.exports = {
1213
'^.+\\.(css|scss)$': 'identity-obj-proxy',
1314
},
1415
setupFilesAfterEnv: ['./scripts/jest/test.config.js'],
15-
testMatch: ['**/packages/**/__test?(s)__/**/*.spec.[jt]s?(x)'],
16+
testMatch: ['**/__test?(s)__/**/*.spec.[jt]s?(x)'],
1617
testPathIgnorePatterns: ['/node_modules/'],
1718
transform: {
1819
'^.+\\.jsx?$': 'babel-jest',

package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@
44
"license": "Apache-2.0",
55
"private": true,
66
"scripts": {
7-
"start:test-site": "http-server -p 8080 ./tests/static",
7+
"start:test-site": "http-server -p 8080 ./packages/side-testkit/fixtures/static",
88
"build": "run-s build:ts build:ide",
9-
"build:electron": "pnpm run --stream --filter @seleniumhq/selenium-ide build:electron",
10-
"build:ide": "pnpm run --stream --filter @seleniumhq/selenium-ide build:webpack",
9+
"build:electron": "pnpm run --stream --filter selenium-ide build:electron",
10+
"build:ide": "pnpm run --stream --filter selenium-ide build:webpack",
1111
"build:js": "pnpm run --stream --filter @seleniumhq/code-export-* build",
1212
"build:ts": "tsc --build --verbose",
1313
"clean:deps": "rimraf packages/*/node_modules node_modules",
1414
"clean": "rimraf packages/*/build packages/*/dist packages/*/node_modules packages/*/tsconfig.tsbuildinfo node_modules",
1515
"clean:nuke": "git clean -fdx",
16+
"pretest": "cd packages/webdriver-testkit && npm run download-drivers",
1617
"start": "cd packages/selenium-ide && npm start",
17-
"test": "jest",
18-
"test:e2e": "jest --testMatch \"**/packages/**/__tests__/**/*.e2e.js\"",
18+
"test:jest:core": "jest",
19+
"test": "npm run test:jest && npm run test:side-runner:ci",
20+
"test:jest": "npm-run-bg -s 'http-server -p 8080 ./packages/side-testkit/fixtures/static::Available on::8080' 'npm run test:jest:core'",
1921
"lint": "pnpm run lint:scripts",
2022
"lint:scripts": "eslint --ignore-pattern node_modules --ignore-pattern third-party --ignore-pattern dist --ignore-pattern build --ignore-pattern json --ext .ts,.tsx --ext .js packages/",
21-
"test:ide": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/selenium-ide/scripts/ide-runner.js -t 15000 ./tests/examples/*.side'",
22-
"test:side-runner": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -t 15000 ./tests/examples/*.side'",
23-
"test:side-runner:ci": "npm-run-bg -s 'http-server -p 8080 ./tests/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -c \"goog:chromeOptions.args=[headless,no-sandbox] browserName=chrome\" -t 15000 ./tests/examples/*.side'",
23+
"test:ide": "npm-run-bg -s 'http-server -p 8080 ./packages/side-testkit/fixtures/static::Available on::8080' 'node ./packages/selenium-ide/scripts/ide-runner.js -t 15000 ./tests/examples/*.side'",
24+
"test:side-runner": "npm-run-bg -s 'http-server -p 8080 ./packages/side-testkit/fixtures/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -t 15000 ./tests/examples/*.side'",
25+
"test:side-runner:ci": "npm-run-bg -s 'http-server -p 8080 ./packages/side-testkit/fixtures/static::Available on::8080' 'node ./packages/side-runner/dist/bin.js -c \"goog:chromeOptions.args=[headless,no-sandbox] browserName=chrome\" -t 15000 ./tests/examples/*.side'",
2426
"typecheck": "tsc --noEmit --composite false",
2527
"watch": "run-p watch:ts watch:webpack",
26-
"watch:webpack": "pnpm run --stream --filter @seleniumhq/selenium-ide watch",
28+
"watch:webpack": "pnpm run --stream --filter selenium-ide watch",
2729
"watch:js": "pnpm run --stream --filter @seleniumhq/code-export-* --loglevel verbose watch",
2830
"watch:ts": "tsc --build --verbose --watch"
2931
},

packages/browser-info/jest.config.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
module.exports = {
2-
testEnvironment: 'jsdom',
32
testEnvironmentOptions: {
43
url: 'http://localhost/index.html',
54
},
6-
moduleNameMapper: {
7-
'^.+\\.(css|scss)$': 'identity-obj-proxy',
8-
},
9-
setupFilesAfterEnv: ['./scripts/jest/test.config.js'],
105
testMatch: ['**/packages/**/__test?(s)__/**/*.spec.[jt]s?(x)'],
11-
testPathIgnorePatterns: ['/node_modules/'],
6+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
127
transform: {
13-
'^.+\\.jsx?$': 'babel-jest',
14-
'^.+\\.tsx?$': 'ts-jest',
8+
'^.+\\.ts?$': 'ts-jest',
159
},
1610
}

packages/browser-info/__tests__/chrome.spec.ts renamed to packages/browser-info/src/__tests__/chrome.spec.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
// under the License.
1717

1818
jest.mock('os')
19-
jest.mock('../src/sh')
19+
jest.mock('../sh')
2020
import * as os from 'os'
21-
import { Chrome } from '../src/chrome'
22-
import { sh, makeError } from '../src/sh'
21+
import { Chrome } from '../chrome'
22+
import { sh, makeError } from '../sh'
2323

2424
const { getBrowserInfo, ChromeChannel } = Chrome
2525
const mockSh = sh as unknown as jest.Mock<any, any>
2626
const mockPlatform = os.platform as unknown as jest.Mock<any, any>
2727

28+
type Success = Chrome.BrowserInfo | Chrome.BrowserInfo[]
29+
2830
describe('chrome browser info', () => {
2931
describe('macOS', () => {
3032
beforeAll(() => {
@@ -39,10 +41,10 @@ describe('chrome browser info', () => {
3941
mockSh.mockReturnValueOnce(
4042
Promise.resolve({ stdout: 'Google Chrome 76.0.3809.132\n', stderr: '' })
4143
)
42-
expect(await getBrowserInfo(ChromeChannel.stable)).toEqual({
44+
expect(await getBrowserInfo(ChromeChannel.stable)).toEqual<Success>({
4345
binary: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
4446
version: '76.0.3809.132',
45-
channel: 'stable',
47+
channel: ChromeChannel.stable,
4648
})
4749
})
4850
it('should fail to get chrome info when its not installed', async () => {
@@ -51,7 +53,9 @@ describe('chrome browser info', () => {
5153
try {
5254
await getBrowserInfo(ChromeChannel.stable)
5355
} catch (err) {
54-
expect(err.message).toBe('Unable to find Chrome installation')
56+
expect((err as Error).message).toBe(
57+
'Unable to find Chrome installation'
58+
)
5559
}
5660
})
5761
it('should get all chrome info', async () => {
@@ -73,24 +77,24 @@ describe('chrome browser info', () => {
7377
})
7478
}
7579
})
76-
expect(await getBrowserInfo()).toEqual([
80+
expect(await getBrowserInfo()).toEqual<Success>([
7781
{
7882
binary:
7983
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
8084
version: '76.0.3809.132',
81-
channel: 'stable',
85+
channel: ChromeChannel.stable,
8286
},
8387
{
8488
binary:
8589
'/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome',
8690
version: '75.0.3770.75',
87-
channel: 'beta',
91+
channel: ChromeChannel.beta,
8892
},
8993
{
9094
binary:
9195
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
9296
version: '79.0.3915.0',
93-
channel: 'canary',
97+
channel: ChromeChannel.canary,
9498
},
9599
])
96100
mockSh.mockReset()
@@ -111,18 +115,18 @@ describe('chrome browser info', () => {
111115
})
112116
}
113117
})
114-
expect(await getBrowserInfo()).toEqual([
118+
expect(await getBrowserInfo()).toEqual<Success>([
115119
{
116120
binary:
117121
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
118122
version: '76.0.3809.132',
119-
channel: 'stable',
123+
channel: ChromeChannel.stable,
120124
},
121125
{
122126
binary:
123127
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
124128
version: '79.0.3915.0',
125-
channel: 'canary',
129+
channel: ChromeChannel.canary,
126130
},
127131
])
128132
mockSh.mockReset()
@@ -153,15 +157,17 @@ describe('chrome browser info', () => {
153157
try {
154158
await getBrowserInfo(ChromeChannel.stable)
155159
} catch (err) {
156-
expect(err.message).toBe('Unable to find Chrome installation')
160+
expect((err as Error).message).toBe(
161+
'Unable to find Chrome installation'
162+
)
157163
}
158164
})
159165
it('should fail to get canary chrome channel since it is not available on linux', async () => {
160166
expect.assertions(1)
161167
try {
162168
await getBrowserInfo(ChromeChannel.canary)
163169
} catch (err) {
164-
expect(err.message).toBe('Unsupported channel canary')
170+
expect((err as Error).message).toBe('Unsupported channel canary')
165171
}
166172
})
167173
it('should get all chrome info', async () => {
@@ -203,11 +209,11 @@ describe('chrome browser info', () => {
203209
})
204210
}
205211
})
206-
expect(await getBrowserInfo()).toEqual([
212+
expect(await getBrowserInfo()).toEqual<Success>([
207213
{
208214
binary: '/usr/local/sbin/google-chrome',
209215
version: '76.0.3809.132',
210-
channel: 'stable',
216+
channel: ChromeChannel.stable,
211217
},
212218
])
213219
mockSh.mockReset()

packages/browser-info/__tests__/index.spec.ts renamed to packages/browser-info/src/__tests__/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import * as index from '../src'
18+
import * as index from '../index'
1919

2020
describe('browser-info', () => {
2121
it('should export all the required things', () => {

packages/browser-info/__tests__/sh.spec.ts renamed to packages/browser-info/src/__tests__/sh.spec.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import { sh } from '../src/sh'
18+
import { ShellError, sh } from '../sh'
1919

2020
describe('sh', () => {
2121
it('should run a process', async () => {
@@ -42,17 +42,19 @@ describe('sh', () => {
4242
'console.log(`out`);console.error(`err`);process.exit(1);',
4343
])
4444
} catch (err) {
45-
expect(err.stdout).toBe('out\n')
46-
expect(err.stderr).toBe('err\n')
47-
expect(err.code).toBe(1)
45+
const error = err as ShellError
46+
expect(error.stdout).toBe('out\n')
47+
expect(error.stderr).toBe('err\n')
48+
expect(error.code).toBe(1)
4849
}
4950
})
5051
it('should fail to start a process that does not exist', async () => {
5152
expect.assertions(1)
5253
try {
5354
await sh('command-that-does-not-exist')
5455
} catch (err) {
55-
expect(err.code).toBe(1)
56+
const error = err as ShellError
57+
expect(error.code).toBe(1)
5658
}
5759
})
5860
})

packages/browser-info/src/chrome.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ export namespace Chrome {
135135
}
136136
}
137137

138-
export interface BrowserInfo {
139-
channel: ChromeChannel
140-
binary: string
141-
version: string
142-
}
143-
144138
export enum ChromeChannel {
145139
stable = 'stable',
146140
beta = 'beta',
147141
canary = 'canary',
148142
}
143+
144+
export interface BrowserInfo {
145+
channel: ChromeChannel
146+
binary: string
147+
version: string
148+
}
149149
}

packages/browser-info/src/sh.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function sh(
2323
args: string[] = [],
2424
options?: object
2525
): Promise<Output> {
26-
let resolve: (value: Output) => void, reject: (reason: Error & Output) => void
26+
let resolve: (value: Output) => void, reject: (reason: ShellError) => void
2727
const p = new Promise<Output>((res, rej) => {
2828
resolve = res
2929
reject = rej
@@ -64,19 +64,21 @@ export function makeError(
6464
stdout: string,
6565
stderr: string
6666
) {
67-
const err = new Error(message) as Error & Output & ErrorWithExitCode
67+
const err = new Error(message) as ShellError
6868
err.stdout = stdout
6969
err.stderr = stderr
7070
err.code = code
7171

7272
return err
7373
}
7474

75-
interface Output {
75+
export interface Output {
7676
stdout: string
7777
stderr: string
7878
}
7979

80-
interface ErrorWithExitCode {
80+
export interface ErrorWithExitCode {
8181
code: number
8282
}
83+
84+
export interface ShellError extends Error, Output, ErrorWithExitCode {}

packages/browser-info/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"include": ["src/**/*.ts"],
1010
"exclude": [
11-
"**/__mocks__",
12-
"**/__tests__"
11+
"**/__mocks__"
1312
]
1413
}

packages/get-driver/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
testEnvironmentOptions: {
3+
url: 'http://localhost/index.html',
4+
},
5+
testMatch: ['**/packages/**/__test?(s)__/**/*.spec.[jt]s?(x)'],
6+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
7+
transform: {
8+
'^.+\\.ts?$': 'ts-jest',
9+
},
10+
}

0 commit comments

Comments
 (0)