How to use parseExitCode method in Karma

Best JavaScript code snippet using karma

Run Karma automation tests on LambdaTest cloud grid

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

runner.spec.js

Source: runner.spec.js Github

copy
1const loadFile = require('mocks').loadFile
2const path = require('path')
3
4const constant = require('../../lib/constants')
5
6describe('runner', () => {
7  let m
8
9  beforeEach(() => {
10    m = loadFile(path.join(__dirname, '/../../lib/runner.js'))
11  })
12
13  describe('parseExitCode', () => {
14    const EXIT = constant.EXIT_CODE
15
16    it('should return 0 exit code if present in the buffer', () => {
17      const result = m.parseExitCode(Buffer.from(`something\nfake${EXIT}10`))
18      expect(result.exitCode).to.equal(0)
19    })
20
21    it('should remove the exit code part of the returned buffer', () => {
22      const buffer = Buffer.from(`some${EXIT}01`)
23      const result = m.parseExitCode(buffer)
24
25      expect(buffer.toString()).to.equal(`some${EXIT}01`)
26      expect(result.buffer.toString()).to.equal('some')
27    })
28
29    it('should not touch buffer without exit code and return default', () => {
30      const msg = 'some nice \n messgae {}'
31      const buffer = Buffer.from(msg)
32      const result = m.parseExitCode(buffer, 10)
33
34      expect(result.buffer.toString()).to.equal(msg)
35      expect(result.buffer).to.equal(buffer)
36      expect(result.exitCode).to.equal(10)
37    })
38
39    it('should not slice buffer if smaller than exit code msg', () => {
40      // regression
41      const fakeBuffer = { length: 1, slice: () => null }
42      sinon.stub(fakeBuffer, 'slice')
43
44      m.parseExitCode(fakeBuffer, 10)
45      expect(fakeBuffer.slice).not.to.have.been.called
46    })
47
48    it('should return same buffer if smaller than exit code msg', () => {
49      // regression
50      const fakeBuffer = { length: 1, slice: () => null }
51      const result = m.parseExitCode(fakeBuffer, 10)
52      expect(fakeBuffer).to.equal(result.buffer)
53    })
54
55    it('should parse any single digit exit code', () => {
56      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}01`)).exitCode).to.equal(1)
57      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}17`)).exitCode).to.equal(7)
58    })
59
60    it('should return exit code 0 if failOnEmptyTestSuite is false and and non-empty int is 0', () => {
61      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}01`), undefined, false).exitCode).to.equal(0)
62    })
63
64    it('should return exit code if failOnEmptyTestSuite is true', () => {
65      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}00`), undefined, true).exitCode).to.equal(0)
66      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}01`), undefined, true).exitCode).to.equal(1)
67      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}07`), undefined, true).exitCode).to.equal(7)
68      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}10`), undefined, true).exitCode).to.equal(0)
69      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}11`), undefined, true).exitCode).to.equal(1)
70      expect(m.parseExitCode(Buffer.from(`something\nfake${EXIT}17`), undefined, true).exitCode).to.equal(7)
71    })
72  })
73})
74
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Karma on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)