-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from Medable/fix-ci-tests
mdctl-core tests
- Loading branch information
Showing
6 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Mdctl core Tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 20.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run test --workspace=@medable/mdctl-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable max-len */ | ||
const { Transform } = require('stream') | ||
|
||
const fs = require('fs'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
const assert = require('assert'), | ||
sinon = require('sinon'), | ||
ExportStream = require('../streams/export_stream'), | ||
Fault = require('../fault'), | ||
{ ExportSection, StreamChunk } = require('../streams/section') | ||
|
||
describe('ExportStream', () => { | ||
let exportStream | ||
|
||
beforeEach(() => { | ||
exportStream = new ExportStream() | ||
}) | ||
|
||
it('should initialize with empty runtimes array and completed set to false', () => { | ||
assert.deepStrictEqual(exportStream.runtimes, []) | ||
assert.strictEqual(exportStream.completed, false) | ||
}) | ||
|
||
it('should return the value of completed property', () => { | ||
assert.strictEqual(exportStream.complete(), false) | ||
exportStream.completed = true | ||
assert.strictEqual(exportStream.complete(), true) | ||
}) | ||
|
||
it('should check if a given name is in the allowed keys', () => { | ||
assert.strictEqual(exportStream.checkKeys('object'), true) | ||
assert.strictEqual(exportStream.checkKeys('facet'), true) | ||
assert.strictEqual(exportStream.checkKeys('app'), true) | ||
assert.strictEqual(exportStream.checkKeys('config'), true) | ||
assert.strictEqual(exportStream.checkKeys('invalid-key'), false) | ||
}) | ||
|
||
it('should transform and push ExportSection when the object is in the allowed keys', () => { | ||
const chunk = { object: 'object' }, | ||
pushSpy = sinon.spy(exportStream, 'push') | ||
|
||
exportStream._transform(chunk, null, () => {}) | ||
|
||
sinon.assert.calledWith(pushSpy, new ExportSection(chunk, chunk.object)) | ||
}) | ||
|
||
it('should transform and push StreamChunk when the object is "stream"', () => { | ||
const chunk = { object: 'stream' }, | ||
pushSpy = sinon.spy(exportStream, 'push') | ||
|
||
exportStream._transform(chunk, null, () => {}) | ||
|
||
sinon.assert.calledWith(pushSpy, new StreamChunk(chunk, chunk.object)) | ||
}) | ||
|
||
it('should add runtime chunk to the runtimes array when the object is "runtime-resource"', () => { | ||
const chunk = { object: 'runtime-resource' } | ||
|
||
exportStream._transform(chunk, null, () => {}) | ||
|
||
assert(exportStream.runtimes.includes(chunk)) | ||
}) | ||
|
||
it('should set completed to true when the object is "manifest-exports"', () => { | ||
const chunk = { object: 'manifest-exports' } | ||
|
||
exportStream._transform(chunk, null, () => {}) | ||
|
||
assert.strictEqual(exportStream.completed, true) | ||
}) | ||
|
||
it('should callback with a Fault when the chunk does not have an object property', () => { | ||
const callback = sinon.stub() | ||
|
||
exportStream._transform({}, null, callback) | ||
|
||
sinon.assert.calledWith(callback, sinon.match.instanceOf(Fault)) | ||
}) | ||
|
||
it('should callback with a Fault when the chunk object is "fault"', () => { | ||
const chunk = { object: 'fault' }, | ||
callback = sinon.stub() | ||
|
||
exportStream._transform(chunk, null, callback) | ||
|
||
sinon.assert.calledWith(callback, sinon.match.instanceOf(Fault)) | ||
}) | ||
|
||
it('should ignore unhandled chunks', () => { | ||
const chunk = { object: 'unhandled' }, | ||
callback = sinon.stub() | ||
|
||
exportStream._transform(chunk, null, callback) | ||
|
||
sinon.assert.calledWith(callback) | ||
}) | ||
|
||
it('should flush the runtimes array as an ExportSection', () => { | ||
const done = sinon.stub(), | ||
pushSpy = sinon.spy(exportStream, 'push') | ||
|
||
exportStream.runtimes = [{ object: 'runtime-resource' }] | ||
|
||
exportStream._flush(done) | ||
|
||
sinon.assert.calledWith(pushSpy, new ExportSection(exportStream.runtimes, 'resources')) | ||
sinon.assert.called(done) | ||
}) | ||
}) |