2018-02-08 05:19:44 +00:00
"use strict" ;
2018-06-15 20:31:06 +00:00
const log = require ( "../../../src/log" ) ;
2018-02-08 05:19:44 +00:00
const expect = require ( "chai" ) . expect ;
2018-03-20 05:54:04 +00:00
const stub = require ( "sinon" ) . stub ;
2018-02-08 05:19:44 +00:00
const TestUtil = require ( "../../util" ) ;
let packages ;
describe ( "packages" , function ( ) {
beforeEach ( function ( ) {
2018-03-20 05:54:04 +00:00
stub ( log , "info" ) ;
2018-02-08 05:19:44 +00:00
delete require . cache [ require . resolve ( "../../../src/plugins/packages" ) ] ;
packages = require ( "../../../src/plugins/packages" ) ;
} ) ;
afterEach ( function ( ) {
2018-03-20 05:54:04 +00:00
log . info . restore ( ) ;
2018-02-08 05:19:44 +00:00
} ) ;
describe ( ".getStylesheets" , function ( ) {
it ( "should contain no stylesheets before packages are loaded" , function ( ) {
expect ( packages . getStylesheets ( ) ) . to . be . empty ;
} ) ;
it ( "should return the list of registered stylesheets for loaded packages" , function ( ) {
packages . loadPackages ( ) ;
expect ( packages . getStylesheets ( ) ) . to . deep . equal ( [
"thelounge-package-foo/style.css" ,
] ) ;
} ) ;
} ) ;
describe ( ".getPackage" , function ( ) {
it ( "should contain no reference to packages before loading them" , function ( ) {
expect ( packages . getPackage ( "thelounge-package-foo" ) ) . to . be . undefined ;
} ) ;
it ( "should return details of a registered package after it was loaded" , function ( ) {
packages . loadPackages ( ) ;
expect ( packages . getPackage ( "thelounge-package-foo" ) )
. to . have . key ( "onServerStart" ) ;
} ) ;
} ) ;
describe ( ".loadPackages" , function ( ) {
it ( "should display report about loading packages" , function ( ) {
// Mock `log.info` to extract its effect into a string
2018-03-20 05:54:04 +00:00
log . info . restore ( ) ;
2018-02-08 05:19:44 +00:00
let stdout = "" ;
2018-03-20 05:54:04 +00:00
stub ( log , "info" ) . callsFake ( TestUtil . sanitizeLog ( ( str ) => stdout += str ) ) ;
2018-02-08 05:19:44 +00:00
packages . loadPackages ( ) ;
2019-07-05 07:26:22 +00:00
expect ( stdout ) . to . deep . equal ( "Package thelounge-package-foo loaded\nThere are packages using the experimental plugin API. Be aware that this API is not yet stable and may change in future The Lounge releases.\n" ) ;
2018-02-08 05:19:44 +00:00
} ) ;
} ) ;
} ) ;