selenium-side-runner 4.0.0-alpha.60 → 4.0.0-alpha.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,23 +15,26 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
+ import { ProxyCapabilities } from '../types'
18
19
  import ParseProxy from '../proxy'
19
20
 
20
21
  describe('proxy parser', () => {
21
22
  it('should parse a direct proxy', () => {
22
- expect(ParseProxy('direct')).toEqual({
23
+ expect(ParseProxy('direct')).toEqual<ProxyCapabilities>({
23
24
  proxyType: 'direct',
24
25
  })
25
26
  })
26
27
  it('should parse a system proxy', () => {
27
- expect(ParseProxy('system')).toEqual({
28
+ expect(ParseProxy('system')).toEqual<ProxyCapabilities>({
28
29
  proxyType: 'system',
29
30
  })
30
31
  })
31
32
  it('should parse a pac proxy', () => {
32
- expect(ParseProxy('pac', 'http://localhost/pac')).toEqual({
33
+ expect(
34
+ ParseProxy('pac', 'http://localhost/pac')
35
+ ).toEqual<ProxyCapabilities>({
33
36
  proxyType: 'pac',
34
- proxyOptions: 'http://localhost/pac',
37
+ proxyAutoconfigUrl: 'http://localhost/pac',
35
38
  })
36
39
  })
37
40
  it('should throw if no pac file was given', () => {
@@ -40,19 +43,16 @@ describe('proxy parser', () => {
40
43
  )
41
44
  })
42
45
  it('should parse a manual proxy', () => {
43
- expect(ParseProxy('manual', {})).toEqual({
46
+ expect(ParseProxy('manual', {})).toEqual<ProxyCapabilities>({
44
47
  proxyType: 'manual',
45
- proxyOptions: {},
46
48
  })
47
49
  })
48
50
  it('should omit redundant keys from the proxy', () => {
49
51
  expect(
50
52
  ParseProxy('manual', { test: 4, http: 'http://localhost:4324' })
51
- ).toEqual({
53
+ ).toEqual<ProxyCapabilities>({
52
54
  proxyType: 'manual',
53
- proxyOptions: {
54
- http: 'http://localhost:4324',
55
- },
55
+ httpProxy: 'http://localhost:4324',
56
56
  })
57
57
  })
58
58
  it('should whitelist the allowed proxy protocols', () => {
@@ -64,20 +64,17 @@ describe('proxy parser', () => {
64
64
  ftp: 'http://localhost:4324',
65
65
  bypass: ['http://something.com'],
66
66
  })
67
- ).toEqual({
67
+ ).toEqual<ProxyCapabilities>({
68
68
  proxyType: 'manual',
69
- proxyOptions: {
70
- http: 'http://localhost:4324',
71
- https: 'http://localhost:4324',
72
- ftp: 'http://localhost:4324',
73
- bypass: ['http://something.com'],
74
- },
69
+ httpProxy: 'http://localhost:4324',
70
+ ftpProxy: 'http://localhost:4324',
71
+ sslProxy: 'http://localhost:4324',
72
+ noProxy: ['http://something.com'],
75
73
  })
76
74
  })
77
75
  it('should return an empty object if no options were given to manual proxy', () => {
78
- expect(ParseProxy('manual')).toEqual({
76
+ expect(ParseProxy('manual')).toEqual<ProxyCapabilities>({
79
77
  proxyType: 'manual',
80
- proxyOptions: {},
81
78
  })
82
79
  })
83
80
  it('should throw if non object was passed to manual proxy type', () => {
@@ -87,31 +84,27 @@ describe('proxy parser', () => {
87
84
  )
88
85
  })
89
86
  it('should parse socks proxy', () => {
90
- expect(ParseProxy('socks', { socksProxy: 'localhost:213' })).toEqual({
91
- proxyType: 'socks',
92
- proxyOptions: {
93
- socksProxy: 'localhost:213',
94
- },
87
+ expect(
88
+ ParseProxy('socks', { socksProxy: 'localhost:213' })
89
+ ).toEqual<ProxyCapabilities>({
90
+ proxyType: 'manual',
91
+ socksProxy: 'localhost:213',
95
92
  })
96
93
  })
97
94
  it('should parse socks proxy version', () => {
98
95
  expect(
99
96
  ParseProxy('socks', { socksProxy: 'localhost:213', socksVersion: 5 })
100
- ).toEqual({
101
- proxyType: 'socks',
102
- proxyOptions: {
103
- socksProxy: 'localhost:213',
104
- socksVersion: 5,
105
- },
97
+ ).toEqual<ProxyCapabilities>({
98
+ proxyType: 'manual',
99
+ socksProxy: 'localhost:213',
100
+ socksVersion: 5,
106
101
  })
107
102
  expect(
108
103
  ParseProxy('socks', { socksProxy: 'localhost:213', socksVersion: '5' })
109
- ).toEqual({
110
- proxyType: 'socks',
111
- proxyOptions: {
112
- socksProxy: 'localhost:213',
113
- socksVersion: 5,
114
- },
104
+ ).toEqual<ProxyCapabilities>({
105
+ proxyType: 'manual',
106
+ socksProxy: 'localhost:213',
107
+ socksVersion: 5,
115
108
  })
116
109
  })
117
110
  it('should throw if no socks proxy url was given', () => {
package/src/bin.ts CHANGED
@@ -191,9 +191,9 @@ configuration.debugStartup &&
191
191
  console.debug('Configuration:', util.inspect(configuration))
192
192
 
193
193
  // All the stuff that goes into a big wrapped jest command
194
- const jest = 'node '+ resolveBin.sync('jest')
194
+ const jest = 'node ' + resolveBin.sync('jest')
195
195
  const jestArgs = [
196
- '--config=' + path.join(__dirname, '..', 'jest.config.js'),
196
+ '--config=' + path.join(__dirname, '..', 'runner.jest.config.js'),
197
197
  '--maxConcurrency=' + configuration.maxWorkers,
198
198
  ]
199
199
  .concat(
@@ -204,7 +204,7 @@ const jestArgs = [
204
204
  ]
205
205
  : []
206
206
  )
207
- .concat(options.jestOptions.slice(1, -1).split(' '))
207
+ .concat(options.jestOptions.slice(1, -1).split(' ').filter(Boolean))
208
208
  .concat(['--runTestsByPath', path.join(__dirname, 'main.test.js')])
209
209
 
210
210
  const jestEnv = {
@@ -215,6 +215,7 @@ const jestEnv = {
215
215
  configuration.debugStartup &&
216
216
  console.debug('Jest command:', jest, jestArgs, jestEnv)
217
217
  spawn(jest, jestArgs, {
218
+ cwd: process.cwd(),
218
219
  env: jestEnv,
219
220
  shell: true,
220
221
  stdio: 'inherit',
@@ -63,7 +63,7 @@ function assignStringKey(key: string, value: string, keyObject: KeyObject) {
63
63
  function parseStringValue(value: string) {
64
64
  // is array
65
65
  if (/^\[.*\]$/.test(value)) {
66
- const matches = value.slice(1, -2).match(/(([^,]*)*)/g) as string[]
66
+ const matches = value.slice(1, -1).match(/(([^,]*)*)/g) as string[]
67
67
  return matches.filter((s) => !!s).map((s) => s.trim())
68
68
  }
69
69
  try {
@@ -81,7 +81,7 @@ function parseStringValue(value: string) {
81
81
  function trimSingleQuote(value: string) {
82
82
  let str = value.trim()
83
83
  if (str[0] === str[str.length - 1] && str[0] === "'") {
84
- return str.slice(1, -2)
84
+ return str.slice(1, -1)
85
85
  }
86
86
  return str
87
87
  }
package/src/main.test.ts CHANGED
@@ -20,13 +20,13 @@ import fs from 'fs'
20
20
  import { globSync } from 'glob'
21
21
  import { createLogger, format, transports } from 'winston'
22
22
  import { Configuration, Project } from './types'
23
- import buildRegister from './register'
24
- import buildRunners from './run'
23
+ import buildRun from './run'
25
24
  import { ProjectShape, SuiteShape, TestShape } from '@seleniumhq/side-model'
26
25
  import {
27
26
  correctPluginPaths,
28
27
  loadPlugins,
29
28
  PluginHooks,
29
+ Variables,
30
30
  } from '@seleniumhq/side-runtime'
31
31
 
32
32
  const metadata = require('../package.json')
@@ -119,15 +119,21 @@ const factoryParams = {
119
119
  configuration,
120
120
  logger: logger as unknown as Console,
121
121
  }
122
- const register = buildRegister(factoryParams)
123
- const runners = buildRunners(factoryParams)
122
+ const getTestByID = (project: ProjectShape) => (testID: string) =>
123
+ project.tests.find((t) => t.id === testID) as TestShape
124
+
125
+ const run = buildRun(factoryParams)
126
+
127
+ let plugins: Awaited<ReturnType<typeof loadPlugins>> | undefined
124
128
  each(projects).describe(projectTitle, (project: Project) => {
125
129
  try {
126
130
  const pluginPaths = correctPluginPaths(project.path, project?.plugins ?? [])
127
131
  const runHook = (hookName: keyof PluginHooks) => async () => {
128
- const plugins = await loadPlugins(pluginPaths)
132
+ if (!plugins) {
133
+ plugins = await loadPlugins(pluginPaths)
134
+ }
129
135
  await Promise.all(
130
- plugins.map(async (plugin) => {
136
+ plugins!.map(async (plugin) => {
131
137
  const hook = plugin.hooks?.[hookName]
132
138
  if (hook) {
133
139
  await hook({ ...factoryParams, project })
@@ -144,14 +150,19 @@ each(projects).describe(projectTitle, (project: Project) => {
144
150
  if (suites.length) {
145
151
  each(suites).describe(suiteTitle, (suite: SuiteShape) => {
146
152
  const isParallel = suite.parallel
147
- const tests = suite.tests.map((tID) => register.test(project, tID))
153
+ const suiteVariables = new Variables()
154
+ const tests = suite.tests.map(getTestByID(project))
148
155
 
149
156
  const testExecutor = each(tests)
150
157
  const testMethod = isParallel
151
158
  ? testExecutor.test.concurrent
152
159
  : testExecutor.test
153
160
  testMethod(testTitle, async (test: TestShape) => {
154
- await runners.test(project, test)
161
+ await run(
162
+ project,
163
+ test,
164
+ suite.persistSession ? suiteVariables : new Variables()
165
+ )
155
166
  })
156
167
  })
157
168
  } else {
@@ -159,9 +170,9 @@ each(projects).describe(projectTitle, (project: Project) => {
159
170
  Project ${project.name} doesn't have any suites matching filter ${configuration.filter},
160
171
  attempting to iterate all tests in project
161
172
  `)
162
- const tests = project.tests
163
- .map((test) => register.test(project, test.id))
164
- .filter((test) => new RegExp(configuration.filter).test(test.name))
173
+ const tests = project.tests.filter((test) =>
174
+ new RegExp(configuration.filter).test(test.name)
175
+ )
165
176
  if (!tests.length) {
166
177
  throw new Error(
167
178
  `No suites or tests found in project ${project.name} matching filter ${configuration.filter}, unable to test!`
@@ -169,7 +180,7 @@ each(projects).describe(projectTitle, (project: Project) => {
169
180
  }
170
181
  const testExecutor = each(tests)
171
182
  testExecutor.test(testTitle, async (test: TestShape) => {
172
- await runners.test(project, test)
183
+ await run(project, test, new Variables())
173
184
  })
174
185
  }
175
186
  } catch (e) {
package/src/run.ts CHANGED
@@ -26,10 +26,9 @@ import {
26
26
  WebDriverExecutor,
27
27
  } from '@seleniumhq/side-runtime'
28
28
  import { WebDriverExecutorConstructorArgs } from '@seleniumhq/side-runtime/dist/webdriver'
29
- import { SuiteShape, TestShape } from '@seleniumhq/side-model'
29
+ import { TestShape } from '@seleniumhq/side-model'
30
30
  import fs from 'fs/promises'
31
31
  import path from 'path'
32
- import Satisfies from './versioner'
33
32
  import { Configuration, Project } from './types'
34
33
 
35
34
  export interface HoistedThings {
@@ -37,8 +36,9 @@ export interface HoistedThings {
37
36
  logger: Console
38
37
  }
39
38
 
40
- const buildRunners = ({ configuration, logger }: HoistedThings) => {
41
- const runTest = async (project: Project, test: TestShape) => {
39
+ const buildRun =
40
+ ({ configuration, logger }: HoistedThings) =>
41
+ async (project: Project, test: TestShape, variables = new Variables()) => {
42
42
  logger.info(`Running test ${test.name}`)
43
43
  const pluginPaths = correctPluginPaths(project.path, project?.plugins ?? [])
44
44
  const plugins = await loadPlugins(pluginPaths)
@@ -73,7 +73,7 @@ const buildRunners = ({ configuration, logger }: HoistedThings) => {
73
73
  getTestByName: (name: string) =>
74
74
  project.tests.find((t) => t.name === name) as TestShape,
75
75
  logger,
76
- variables: new Variables(),
76
+ variables,
77
77
  })
78
78
  const onComplete = async (failure: any) => {
79
79
  // I know this feature is over aggressive for a tool to be deprecated
@@ -165,56 +165,4 @@ const buildRunners = ({ configuration, logger }: HoistedThings) => {
165
165
  }
166
166
  }
167
167
 
168
- const runSuite = async (project: Project, suite: SuiteShape) => {
169
- logger.info(`Running suite ${suite.name}`)
170
- if (!suite.tests.length) {
171
- throw new Error(
172
- `The suite ${suite.name} has no tests, add tests to the suite using the IDE.`
173
- )
174
- }
175
- for (let i = 0, ii = suite.tests.length; i != ii; i++) {
176
- await runTest(
177
- project,
178
- project.tests.find((t) => t.id === suite.tests[i]) as TestShape
179
- )
180
- }
181
- logger.info(`Finished suite ${suite.name}`)
182
- }
183
-
184
- const runProject = async (project: Project) => {
185
- logger.info(`Running project ${project.name}`)
186
- if (!configuration.force) {
187
- let warning = Satisfies(project.version, '2.0')
188
- if (warning) {
189
- logger.warn(warning)
190
- }
191
- } else {
192
- logger.warn("--force is set, ignoring project's version")
193
- }
194
- if (!project.suites.length) {
195
- throw new Error(
196
- `The project ${project.name} has no test suites defined, create a suite using the IDE.`
197
- )
198
- }
199
-
200
- for (let i = 0, ii = project.suites.length; i != ii; i++) {
201
- await runSuite(project, project.suites[i])
202
- }
203
- logger.info(`Finished project ${project.name}`)
204
- }
205
-
206
- const runAll = async (projects: Project[]) => {
207
- for (let i = 0, ii = projects.length; i != ii; i++) {
208
- await runProject(projects[i])
209
- }
210
- }
211
-
212
- return {
213
- all: runAll,
214
- project: runProject,
215
- suite: runSuite,
216
- test: runTest,
217
- }
218
- }
219
-
220
- export default buildRunners
168
+ export default buildRun