-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests and GitHub Actions step to run them #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: CI | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Run unit tests | ||
run: npm test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const assert = require('assert'); | ||
const InfluxDBReporter = require('../src/influxdb-reporter'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
describe('InfluxDBReporter', function() { | ||
let reporter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
let newmanEmitter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
let reporterOptions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
let options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
beforeEach(function() { | ||
newmanEmitter = { | ||
on: function(event, callback) { | ||
// Mock implementation of newmanEmitter.on | ||
} | ||
}; | ||
reporterOptions = { | ||
influxdbServer: 'localhost', | ||
influxdbPort: 8086, | ||
influxdbName: 'test_db', | ||
influxdbMeasurement: 'test_measurement' | ||
}; | ||
options = { | ||
collection: { | ||
name: 'Test Collection' | ||
} | ||
}; | ||
reporter = new InfluxDBReporter(newmanEmitter, reporterOptions, options); | ||
}); | ||
|
||
describe('start', function() { | ||
it('should initialize context and service', function() { | ||
reporter.start(); | ||
assert.strictEqual(reporter.context.server, 'localhost'); | ||
assert.strictEqual(reporter.context.port, 8086); | ||
assert.strictEqual(reporter.context.name, 'test_db'); | ||
assert.strictEqual(reporter.context.measurement, 'test_measurement'); | ||
}); | ||
}); | ||
|
||
describe('beforeItem', function() { | ||
it('should update currentItem and list', function() { | ||
reporter.beforeItem(); | ||
assert.strictEqual(reporter.context.currentItem.index, 1); | ||
assert.strictEqual(reporter.context.list.length, 1); | ||
}); | ||
}); | ||
|
||
describe('request', function() { | ||
it('should update currentItem data', function() { | ||
const args = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
cursor: {}, | ||
item: { name: 'Test Item' }, | ||
request: { url: { toString: () => 'http://example.com' }, method: 'GET' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6'). |
||
response: { status: 'OK', code: 200, responseTime: 100, responseSize: 1000 } | ||
}; | ||
reporter.request(null, args); | ||
assert.strictEqual(reporter.context.currentItem.data.request_name, 'Test Item'); | ||
assert.strictEqual(reporter.context.currentItem.data.url, 'http://example.com'); | ||
assert.strictEqual(reporter.context.currentItem.data.method, 'GET'); | ||
assert.strictEqual(reporter.context.currentItem.data.status, 'OK'); | ||
assert.strictEqual(reporter.context.currentItem.data.code, 200); | ||
assert.strictEqual(reporter.context.currentItem.data.response_time, 100); | ||
assert.strictEqual(reporter.context.currentItem.data.response_size, 1000); | ||
}); | ||
}); | ||
|
||
describe('assertion', function() { | ||
it('should update currentItem data for failed assertion', function() { | ||
const error = { test: 'Test Assertion', name: 'AssertionError', message: 'Test failed' }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
reporter.assertion(error); | ||
assert.strictEqual(reporter.context.currentItem.data.test_status, 'FAIL'); | ||
assert.strictEqual(reporter.context.currentItem.data.failed.length, 1); | ||
}); | ||
|
||
it('should update currentItem data for skipped assertion', function() { | ||
const args = { skipped: true, assertion: 'Test Assertion' }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
reporter.assertion(null, args); | ||
assert.strictEqual(reporter.context.currentItem.data.test_status, 'SKIP'); | ||
assert.strictEqual(reporter.context.currentItem.data.skipped.length, 1); | ||
}); | ||
}); | ||
|
||
describe('item', function() { | ||
it('should send data to service', function() { | ||
reporter.service = { | ||
sendData: function(data) { | ||
assert.ok(data.includes('test_measurement')); | ||
} | ||
}; | ||
reporter.item(); | ||
}); | ||
}); | ||
|
||
describe('done', function() { | ||
it('should disconnect service', function() { | ||
reporter.service = { | ||
disconnect: function() { | ||
assert.ok(true); | ||
} | ||
}; | ||
reporter.done(); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).