diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/conf/ConfLoaderTest.ts (renamed from test/conf/ConfLoaderTest.js) | 76 |
1 files changed, 48 insertions, 28 deletions
diff --git a/test/conf/ConfLoaderTest.js b/test/conf/ConfLoaderTest.ts index b942216..4d71301 100644 --- a/test/conf/ConfLoaderTest.js +++ b/test/conf/ConfLoaderTest.ts @@ -1,15 +1,34 @@ /** * Tests ConfLoader + * + * Copyright (C) 2010-2019 R-T Specialty, LLC. + * + * This file is part of the Liza Data Collection Framework. + * + * liza is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -'use strict'; +const chai = require( 'chai' ); +const expect = chai.expect; + +import { readFile } from "fs"; + +import { ConfLoader as Sut } from "../../src/conf/ConfLoader"; + +type FsLike = { readFile: typeof readFile }; -const chai = require( 'chai' ); -const expect = chai.expect; const { - conf: { - ConfLoader: Sut, - }, store: { MemoryStore: Store, }, @@ -25,8 +44,8 @@ describe( 'ConfLoader', () => const expected_path = "/foo/bar/baz.json"; const expected_data = '{ "foo": "bar" }'; - const fs = { - readFile( path, encoding, callback ) + const fs = <FsLike>{ + readFile( path: string, encoding: string, callback: any ) { expect( path ).to.equal( expected_path ); expect( encoding ).to.equal( 'utf8' ); @@ -36,7 +55,7 @@ describe( 'ConfLoader', () => }; return expect( - Sut( fs, Store ) + new Sut( fs, Store ) .fromFile( expected_path ) .then( conf => conf.get( 'foo' ) ) ).to.eventually.deep.equal( JSON.parse( expected_data ).foo ); @@ -47,14 +66,14 @@ describe( 'ConfLoader', () => { const expected_err = Error( 'rejected' ); - const fs = { - readFile( _, __, callback ) + const fs = <FsLike>{ + readFile( _: any, __: any, callback: any ) { callback( expected_err, null ); }, }; - return expect( Sut( fs ).fromFile( '' ) ) + return expect( new Sut( fs, Store ).fromFile( '' ) ) .to.eventually.be.rejectedWith( expected_err ); } ); @@ -64,21 +83,21 @@ describe( 'ConfLoader', () => const result = { foo: {} }; const input = "foo"; - const fs = { - readFile( _, __, callback ) + const fs = <FsLike>{ + readFile( _: any, __: any, callback: any ) { callback( null, input ); }, }; - const sut = Sut.extend( + const sut = new class extends Sut { - 'override parseConfData'( given_input ) + parseConfData( given_input: string ) { expect( given_input ).to.equal( input ); return Promise.resolve( result ); - }, - } )( fs, Store ); + } + }( fs, Store ); return expect( sut.fromFile( '' ) @@ -91,8 +110,8 @@ describe( 'ConfLoader', () => { const expected_err = SyntaxError( 'test parsing error' ); - const fs = { - readFile( _, __, callback ) + const fs = <FsLike>{ + readFile( _: any, __: any, callback: any ) { // make async so that we clear the stack, and therefore // try/catch @@ -100,13 +119,13 @@ describe( 'ConfLoader', () => }, }; - const sut = Sut.extend( + const sut = new class extends Sut { - 'override parseConfData'( given_input ) + parseConfData( _given_input: string ): never { throw expected_err; - }, - } )( fs, Store ); + } + }( fs, Store ); return expect( sut.fromFile( '' ) ) .to.eventually.be.rejectedWith( expected_err ); @@ -117,20 +136,21 @@ describe( 'ConfLoader', () => { const expected_err = Error( 'test Store ctor error' ); - const fs = { - readFile: ( _, __, callback ) => callback( null, '' ), + const fs = <FsLike>{ + readFile: ( _: any, __: any, callback: any ) => + callback( null, '' ), }; const badstore = () => { throw expected_err }; - return expect( Sut( fs, badstore ).fromFile( '' ) ) + return expect( new Sut( fs, badstore ).fromFile( '' ) ) .to.eventually.be.rejectedWith( expected_err ); } ); it( "rejects promise on bad fs call", () => { - return expect( Sut( {}, Store ).fromFile( '' ) ) + return expect( new Sut( <FsLike>{}, Store ).fromFile( '' ) ) .to.eventually.be.rejected; } ); } ); |