How to use onPrepare method in stryker-parent

Best JavaScript code snippet using stryker-parent

launcher.test.ts

Source:launcher.test.ts Github

copy

Full Screen

...54 describe('onPrepare', () => {55 it('should set correct starting options', async () => {56 const launcher = new ChromeDriverLauncher(options, capabilities, config)57 launcher._redirectLogStream = vi.fn()58 await launcher.onPrepare()59 expect(vi.mocked(spawn).mock.calls[0][0]).toEqual('/some/local/chromedriver/path')60 expect(vi.mocked(spawn).mock.calls[0][1]).toEqual(['--port=9515', '--url-base=/'])61 })62 it('should be able to do the same when using CJS module', async () => {63 const launcher = new CJSLauncher(options, capabilities, config)64 await launcher.onPrepare()65 expect(vi.mocked(spawn).mock.calls[0][0]).toEqual('/some/local/chromedriver/path')66 expect(vi.mocked(spawn).mock.calls[0][1]).toEqual(['--port=9515', '--url-base=/'])67 })68 it('should fallback to global chromedriver', async () => {69 vi.mocked(fs.existsSync).mockReturnValueOnce(false)70 const launcher = new ChromeDriverLauncher(options, capabilities, config)71 launcher._redirectLogStream = vi.fn()72 await launcher.onPrepare()73 expect(vi.mocked(spawn).mock.calls[0][0]).toEqual('chromedriver')74 })75 it('should set (and overwrite config.outputDir) outputDir when passed in the options', async () => {76 options.outputDir = 'options-outputdir'77 config.outputDir = 'config-outputdir'78 const launcher = new ChromeDriverLauncher(options, capabilities, config)79 launcher._redirectLogStream = vi.fn()80 await launcher.onPrepare()81 expect(launcher['outputDir']).toEqual('options-outputdir')82 })83 it('should set path when passed in the options', async () => {84 options.path = 'options-path'85 const launcher = new ChromeDriverLauncher(options, capabilities, config)86 launcher._redirectLogStream = vi.fn()87 await launcher.onPrepare()88 expect(launcher['capabilities']).toEqual([89 {90 browserName: 'chrome',91 protocol: 'http',92 hostname: 'localhost',93 port: 9515,94 path: 'options-path'95 },96 {97 browserName: 'firefox'98 }99 ])100 })101 it('should set port when passed in the options', async () => {102 options.port = 7676103 const launcher = new ChromeDriverLauncher(options, capabilities, config)104 launcher._redirectLogStream = vi.fn()105 await launcher.onPrepare()106 expect(launcher['capabilities']).toEqual([107 {108 browserName: 'chrome',109 protocol: 'http',110 hostname: 'localhost',111 port: 7676,112 path: '/'113 },114 {115 browserName: 'firefox'116 }117 ])118 })119 it('should set protocol when passed in the options', async () => {120 options.protocol = 'https'121 const launcher = new ChromeDriverLauncher(options, capabilities, config)122 launcher._redirectLogStream = vi.fn()123 await launcher.onPrepare()124 expect(launcher['capabilities']).toEqual([125 {126 browserName: 'chrome',127 protocol: 'https',128 hostname: 'localhost',129 port: 9515,130 path: '/'131 },132 {133 browserName: 'firefox'134 }135 ])136 })137 it('should set hostname when passed in the options', async () => {138 options.hostname = 'dummy'139 const launcher = new ChromeDriverLauncher(options, capabilities, config)140 launcher._redirectLogStream = vi.fn()141 await launcher.onPrepare()142 expect(launcher['capabilities']).toEqual([143 {144 browserName: 'chrome',145 protocol: 'http',146 hostname: 'dummy',147 port: 9515,148 path: '/'149 },150 {151 browserName: 'firefox'152 }153 ])154 })155 it('should set capabilities', async () => {156 const launcher = new ChromeDriverLauncher(options, capabilities, config)157 launcher._redirectLogStream = vi.fn()158 await launcher.onPrepare()159 expect(launcher['capabilities']).toEqual([160 {161 browserName: 'chrome',162 protocol: 'http',163 hostname: 'localhost',164 port: 9515,165 path: '/'166 },167 {168 browserName: 'firefox'169 }170 ])171 })172 it('should set capabilities when using multiremote', async () => {173 const launcher = new ChromeDriverLauncher(options, multiremoteCaps, config)174 launcher._redirectLogStream = vi.fn()175 await launcher.onPrepare()176 expect(launcher['capabilities']).toEqual({177 myCustomChromeBrowser: {178 protocol: 'http',179 hostname: 'localhost',180 port: 9515,181 path: '/',182 capabilities: {183 browserName: 'chrome',184 }185 },186 myCustomFirefoxBrowser: {187 capabilities: {188 browserName: 'firefox'189 }190 },191 myCustomAppium: {192 capabilities: {193 'platformName': 'android',194 }195 }196 })197 })198 it('should set capabilities when the browserName is not lowercase', async () => {199 capabilities.map(cap => {200 if (cap.browserName === 'chrome') {201 cap.browserName = 'Chrome'202 }203 })204 const launcher = new ChromeDriverLauncher(options, capabilities, config)205 launcher._redirectLogStream = vi.fn()206 await launcher.onPrepare()207 expect(launcher['capabilities']).toEqual([208 {209 browserName: 'Chrome',210 protocol: 'http',211 hostname: 'localhost',212 port: 9515,213 path: '/'214 },215 {216 browserName: 'firefox'217 }218 ])219 })220 it('should set correct config properties', async () => {221 config.outputDir = 'dummy'222 const launcher = new ChromeDriverLauncher(options, capabilities, config)223 launcher._redirectLogStream = vi.fn()224 await launcher.onPrepare()225 expect(launcher['outputDir']).toEqual('dummy')226 })227 it('should set correct port and path', async () => {228 const launcher = new ChromeDriverLauncher(options, capabilities, config)229 launcher._redirectLogStream = vi.fn()230 await launcher.onPrepare()231 expect(launcher['args']).toEqual(['--port=9515', '--url-base=/'])232 })233 it('should set correct args', async () => {234 options.args = ['--silent']235 const launcher = new ChromeDriverLauncher(options, capabilities, config)236 launcher._redirectLogStream = vi.fn()237 await launcher.onPrepare()238 expect(launcher['args']).toEqual(['--silent', '--port=9515', '--url-base=/'])239 })240 it('should throw if the argument "--port" is passed', async () => {241 options.args = ['--port=9616']242 const launcher = new ChromeDriverLauncher(options, capabilities, config)243 launcher._redirectLogStream = vi.fn()244 await expect(launcher.onPrepare()).rejects.toThrow(new Error('Argument "--port" already exists'))245 })246 it('should throw if port is not free', async () => {247 const launcher = new ChromeDriverLauncher(options, capabilities, config)248 vi.mocked(tcpPortUsed.waitUntilFree).mockRejectedValueOnce(new Error('timeout'))249 const err = await launcher.onPrepare().catch((err) => err)250 expect(err.message).toContain('Please check if port 9515 is in use!')251 })252 it('should throw if Chromedriver fails to start', async () => {253 const launcher = new ChromeDriverLauncher(options, capabilities, config)254 vi.mocked(tcpPortUsed.waitUntilUsed).mockRejectedValueOnce(new Error('timeout'))255 const err = await launcher.onPrepare().catch((err) => err)256 expect(err.message).toContain('Chromedriver failed to start.')257 })258 it('should throw if the argument "--url-base" is passed', async () => {259 options.args = ['--url-base=/dummy']260 const launcher = new ChromeDriverLauncher(options, capabilities, config)261 launcher._redirectLogStream = vi.fn()262 await expect(launcher.onPrepare()).rejects.toThrow(new Error('Argument "--url-base" already exists'))263 })264 it('should set correct config properties when empty', async () => {265 const launcher = new ChromeDriverLauncher(options, capabilities, config)266 launcher._redirectLogStream = vi.fn()267 await launcher.onPrepare()268 expect(launcher['args']).toBeUndefined269 })270 it('should call ChromeDriver start', async () => {271 const launcher = new ChromeDriverLauncher(options, capabilities, config)272 launcher._redirectLogStream = vi.fn()273 await launcher.onPrepare()274 expect(vi.mocked(spawn).mock.calls[0][1]).toEqual(['--port=9515', '--url-base=/'])275 })276 it('should not output the log file', async () => {277 const launcher = new ChromeDriverLauncher(options, capabilities, config)278 launcher._redirectLogStream = vi.fn()279 await launcher.onPrepare()280 expect(launcher._redirectLogStream).not.toBeCalled()281 })282 it('should output the log file', async () => {283 options.outputDir = 'dummy'284 const launcher = new ChromeDriverLauncher(options, capabilities, config)285 launcher._redirectLogStream = vi.fn()286 await launcher.onPrepare()287 expect(launcher._redirectLogStream).toBeCalled()288 })289 })290 describe('onComplete', () => {291 it('should call ChromeDriver.stop', async () => {292 const launcher = new ChromeDriverLauncher(options, capabilities, config)293 launcher._redirectLogStream = vi.fn()294 await launcher.onPrepare()295 launcher.onComplete()296 expect(vi.mocked(launcher['process']!).kill).toBeCalled()297 })298 it('should not call process.kill', () => {299 const launcher = new ChromeDriverLauncher(options, capabilities, config)300 launcher.onComplete()301 expect(launcher['process']).toBeFalsy()302 })303 })304 describe('_redirectLogStream', () => {305 it('should write output to file', async () => {306 config.outputDir = 'dummy'307 const launcher = new ChromeDriverLauncher(options, capabilities, config)308 await launcher.onPrepare()309 expect(vi.mocked(fs.createWriteStream).mock.calls[0][0]).toBe(path.join(process.cwd(), 'dummy', 'wdio-chromedriver.log'))310 expect(vi.mocked(launcher['process']!).stdout.pipe).toBeCalled()311 expect(vi.mocked(launcher['process']!).stderr.pipe).toBeCalled()312 })313 })314 describe('custom chromedriver Path', () => {315 it('should select custom chromedriver path "chromedriver.exe"', async () => {316 options.chromedriverCustomPath = 'chromedriver.exe'317 const launcher = new ChromeDriverLauncher(options, capabilities, config)318 launcher._redirectLogStream = vi.fn()319 await launcher.onPrepare()320 expect(spawn).toBeCalledWith(321 path.resolve(options.chromedriverCustomPath),322 [ '--port=9515', '--url-base=/' ]323 )324 })325 it('should select custom chromedriver path "c:\\chromedriver.exe"', async () => {326 options.chromedriverCustomPath = 'c:\\chromedriver.exe'327 const launcher = new ChromeDriverLauncher(options, capabilities, config)328 launcher._redirectLogStream = vi.fn()329 await launcher.onPrepare()330 expect(spawn).toBeCalledWith(331 path.resolve(options.chromedriverCustomPath),332 [ '--port=9515', '--url-base=/' ]333 )334 })335 it('should select custom chromedriver path "./chromedriver.exe"', async () => {336 options.chromedriverCustomPath = './chromedriver.exe'337 const launcher = new ChromeDriverLauncher(options, capabilities, config)338 launcher._redirectLogStream = vi.fn()339 await launcher.onPrepare()340 expect(spawn).toBeCalledWith(341 path.resolve(options.chromedriverCustomPath),342 [ '--port=9515', '--url-base=/' ]343 )344 })345 it('should select default chromedriver path if no custom path provided"', async () => {346 options.chromedriverCustomPath = undefined347 const launcher = new ChromeDriverLauncher(options, capabilities, config)348 launcher._redirectLogStream = vi.fn()349 await launcher.onPrepare()350 expect(spawn).toBeCalledWith(351 '/some/local/chromedriver/path',352 [ '--port=9515', '--url-base=/' ]353 )354 })355 /**356 * dynamic changes of mock don't work in vitest357 */358 it.skip('should throw if chromedriver not installed and no custom path provided"', async () => {359 vi.mock('chromedriver', () => { throw new Error('not found') })360 delete options.chromedriverCustomPath361 const launcher = new ChromeDriverLauncher(options, capabilities, config)362 const err = await launcher.onPrepare().catch((err) => err)363 expect(err.name).toBe('SevereServiceError')364 expect(err.message).toContain('not found')365 })366 })...

Full Screen

Full Screen

launcher.test.js

Source:launcher.test.js Github

copy

Full Screen

...12 }13 }14 const service = new SauceServiceLauncher()15 expect(service.sauceConnectProcess).toBeUndefined()16 service.onPrepare(config, caps)17 expect(caps).toEqual([{ tunnelIdentifier: 'my-tunnel' }])18 expect(service.sauceConnectProcess).not.toBeUndefined()19 expect(SauceConnectLauncher).toBeCalled()20})21test('onPrepare w/o identifier', () => {22 const caps = [{}]23 const config = {24 user: 'foobaruser',25 key: '12345',26 sauceConnect: true27 }28 const service = new SauceServiceLauncher()29 expect(service.sauceConnectProcess).toBeUndefined()30 service.onPrepare(config, caps)31 expect(caps).toEqual([{}])32 expect(service.sauceConnectProcess).not.toBeUndefined()33 expect(SauceConnectLauncher).toBeCalled()34})35test('onPrepare multiremote', () => {36 const caps = {37 browserA: {38 capabilities: { browserName: 'chrome' }39 },40 browserB: {41 capabilities: { browserName: 'firefox', tunnelIdentifier: 'fish' }42 }43 }44 const config = {45 user: 'foobaruser',46 key: '12345',47 sauceConnect: true,48 sauceConnectOpts: {49 port: 4446,50 tunnelIdentifier: 'my-tunnel'51 }52 }53 const service = new SauceServiceLauncher()54 expect(service.sauceConnectProcess).toBeUndefined()55 service.onPrepare(config, caps)56 expect(caps).toEqual({57 browserA: {58 capabilities: { browserName: 'chrome', tunnelIdentifier: 'my-tunnel' }59 },60 browserB: {61 capabilities: { browserName: 'firefox', tunnelIdentifier: 'fish' }62 }63 })64 expect(service.sauceConnectProcess).not.toBeUndefined()65 expect(config.port).toBe(4446)66 expect(config.protocol).toBe('http')67 expect(config.hostname).toBe('localhost')68})69test('onPrepare if sauceTunnel is not set', () => {70 const caps = [{}]71 const config = {72 user: 'foobaruser',73 key: '12345',74 sauceConnectOpts: {75 port: 4446,76 tunnelIdentifier: 'my-tunnel'77 }78 }79 const service = new SauceServiceLauncher()80 expect(service.sauceConnectProcess).toBeUndefined()81 service.onPrepare(config, caps)82 expect(caps).toEqual([{}])83 expect(service.sauceConnectProcess).toBeUndefined()84 expect(SauceConnectLauncher).not.toBeCalled()85})86test('onPrepare multiremote with tunnel identifier and with w3c caps ', () => {87 const caps = {88 browserA: {89 capabilities: {90 browserName: 'chrome',91 'sauce:options': {92 commandTimeout: 60093 }94 }95 },96 browserB: {97 capabilities: {98 browserName: 'firefox',99 'sauce:options': {100 commandTimeout: 600,101 tunnelIdentifier: 'fish'102 }103 }104 }105 }106 const config = {107 user: 'foobaruser',108 key: '12345',109 sauceConnect: true,110 sauceConnectOpts: {111 port: 4446,112 tunnelIdentifier: 'my-tunnel'113 }114 }115 const service = new SauceServiceLauncher()116 expect(service.sauceConnectProcess).toBeUndefined()117 service.onPrepare(config, caps)118 expect(caps).toEqual({119 browserA: {120 capabilities: {121 browserName: 'chrome',122 'sauce:options': {123 commandTimeout: 600,124 tunnelIdentifier: 'my-tunnel'125 }126 }127 },128 browserB: {129 capabilities: {130 browserName: 'firefox',131 'sauce:options': {132 commandTimeout: 600,133 tunnelIdentifier: 'fish'134 }135 }136 }137 })138 expect(service.sauceConnectProcess).not.toBeUndefined()139 expect(config.port).toBe(4446)140 expect(config.protocol).toBe('http')141 expect(config.hostname).toBe('localhost')142})143test('onPrepare with tunnel identifier and without w3c caps ', () => {144 const caps = [{145 browserName: 'chrome'146 }, {147 browserName: 'firefox',148 tunnelIdentifier: 'fish'149 }]150 const config = {151 user: 'foobaruser',152 key: '12345',153 sauceConnect: true,154 sauceConnectOpts: {155 port: 4446,156 tunnelIdentifier: 'my-tunnel'157 }158 }159 const service = new SauceServiceLauncher()160 expect(service.sauceConnectProcess).toBeUndefined()161 service.onPrepare(config, caps)162 expect(caps).toEqual([{163 browserName: 'chrome',164 tunnelIdentifier: 'my-tunnel'165 }, {166 browserName: 'firefox',167 tunnelIdentifier: 'fish'168 }])169 expect(service.sauceConnectProcess).not.toBeUndefined()170 expect(config.port).toBe(4446)171 expect(config.protocol).toBe('http')172 expect(config.hostname).toBe('localhost')173})174test('onPrepare without tunnel identifier and without w3c caps ', () => {175 const caps = [{176 browserName: 'chrome'177 }, {178 browserName: 'firefox',179 tunnelIdentifier: 'fish'180 }]181 const config = {182 user: 'foobaruser',183 key: '12345',184 sauceConnect: false185 }186 const service = new SauceServiceLauncher()187 expect(service.sauceConnectProcess).toBeUndefined()188 service.onPrepare(config, caps)189 expect(caps).toEqual([{190 browserName: 'chrome'191 }, {192 browserName: 'firefox',193 tunnelIdentifier: 'fish'194 }])195 expect(service.sauceConnectProcess).toBeUndefined()196})197test('onPrepare without tunnel identifier and with w3c caps ', () => {198 const caps = [{199 browserName: 'chrome',200 'sauce:options': {201 commandTimeout: 600,202 tunnelIdentifier: 'fish'203 }204 }, {205 browserName: 'firefox',206 'sauce:options': {207 commandTimeout: 600208 }209 }]210 const config = {211 user: 'foobaruser',212 key: '12345',213 sauceConnect: false214 }215 const service = new SauceServiceLauncher()216 expect(service.sauceConnectProcess).toBeUndefined()217 service.onPrepare(config, caps)218 expect(caps).toEqual([{219 browserName: 'chrome',220 'sauce:options': {221 commandTimeout: 600,222 tunnelIdentifier: 'fish'223 }224 }, {225 browserName: 'firefox',226 'sauce:options': {227 commandTimeout: 600228 }229 }])230 expect(service.sauceConnectProcess).toBeUndefined()231})232test('onPrepare with tunnel identifier and with w3c caps ', () => {233 const caps = [{234 browserName: 'chrome',235 'sauce:options': {236 commandTimeout: 600,237 tunnelIdentifier: 'fish'238 }239 }, {240 browserName: 'firefox',241 'sauce:options': {242 commandTimeout: 600243 }244 }]245 const config = {246 user: 'foobaruser',247 key: '12345',248 sauceConnect: true,249 sauceConnectOpts: {250 port: 4446,251 tunnelIdentifier: 'my-tunnel'252 }253 }254 const service = new SauceServiceLauncher()255 expect(service.sauceConnectProcess).toBeUndefined()256 service.onPrepare(config, caps)257 expect(caps).toEqual([{258 browserName: 'chrome',259 'sauce:options': {260 commandTimeout: 600,261 tunnelIdentifier: 'fish'262 }263 }, {264 browserName: 'firefox',265 'sauce:options': {266 commandTimeout: 600,267 tunnelIdentifier: 'my-tunnel'268 }269 }])270 expect(service.sauceConnectProcess).not.toBeUndefined()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function (config) {2 config.set({3 });4}5module.exports = function (config) {6 config.set({7 });8}9module.exports = function (config) {10 config.set({11 mochaOptions: {12 }13 });14}15module.exports = function (config) {16 config.set({17 mochaOptions: {18 },19 });20}21module.exports = function (config) {22 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1var Stryker = require('stryker-parent');2var stryker = new Stryker({3});4stryker.runMutationTest();5module.exports = function (config) {6 config.set({7 });8};9module.exports = function (config) {10 config.set({11 });12};13module.exports = function (config) {14 config.set({15 });16};17module.exports = function (config) {18 config.set({19 });20};21module.exports = function (config) {22 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { exec } = require('child_process');2exports.config = {3 onPrepare: function () {4 return new Promise((resolve, reject) => {5 exec('npm run build', (error, stdout, stderr) => {6 if (error) {7 console.error(`exec error: ${error}`);8 return;9 }10 console.log(`stdout: ${stdout}`);11 console.log(`stderr: ${stderr}`);12 resolve();13 });14 });15 }16};17exports.config = {18 onPrepare: function () {19 return new Promise((resolve, reject) => {20 exec('npm run build', (error, stdout, stderr) => {21 if (error) {22 console.error(`exec error: ${error}`);23 return;24 }25 console.log(`stdout: ${stdout}`);26 console.log(`stderr: ${stderr}`);27 resolve();28 });29 });30 }31};

Full Screen

Using AI Code Generation

copy

Full Screen

1exports.config = {2 onPrepare: function() {3 }4};5exports.config = {6 onPrepare: function() {7 }8};9module.exports = function(config) {10 config.set({11 karma: {12 config: {13 },14 },15 });16};17module.exports = function(config) {18 config.set({19 karma: {20 config: {21 },22 },23 commandRunner: {24 }

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(config){2 config.set({3 onPrepare: function() {4 return new Promise(function(resolve, reject) {5 setTimeout(function() {6 console.log('done');7 resolve();8 }, 1000);9 });10 }11 });12};13module.exports = function(config) {14 config.set({15 karma: {16 config: {17 }18 }19 });20};

Full Screen

Using AI Code Generation

copy

Full Screen

1exports.config = {2 onPrepare: function() {3 }4}5exports.config = {6 onPrepare: function() {7 }8}9exports.config = {10 onPrepare: function() {11 }12}13exports.config = {14 onPrepare: function() {15 }16}17exports.config = {18 onPrepare: function() {19 }20}21exports.config = {22 onPrepare: function() {23 }24}25exports.config = {26 onPrepare: function() {27 }28}29exports.config = {30 onPrepare: function() {31 }32}33exports.config = {34 onPrepare: function() {35 }36}37exports.config = {38 onPrepare: function() {39 }40}41exports.config = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful