2022-06-19 00:25:21 +00:00
import log from "../../../server/log" ;
import { expect } from "chai" ;
import TestUtil from "../../util" ;
import sinon from "ts-sinon" ;
import packagePlugin from "../../../server/plugins/packages" ;
2018-02-08 05:19:44 +00:00
2022-06-19 00:25:21 +00:00
let packages : typeof packagePlugin ;
2018-02-08 05:19:44 +00:00
2020-03-21 20:55:36 +00:00
describe ( "packages" , function ( ) {
2022-06-19 00:25:21 +00:00
let logInfoStub : sinon.SinonStub < string [ ] , void > ;
2020-03-21 20:55:36 +00:00
beforeEach ( function ( ) {
2022-06-19 00:25:21 +00:00
logInfoStub = sinon . stub ( log , "info" ) ;
2018-02-08 05:19:44 +00:00
2022-06-19 00:25:21 +00:00
delete require . cache [ require . resolve ( "../../../server/plugins/packages" ) ] ;
// eslint-disable-next-line @typescript-eslint/no-var-requires
packages = require ( "../../../server/plugins/packages" ) . default ;
2018-02-08 05:19:44 +00:00
} ) ;
2020-03-21 20:55:36 +00:00
afterEach ( function ( ) {
2022-06-19 00:25:21 +00:00
logInfoStub . restore ( ) ;
2018-02-08 05:19:44 +00:00
} ) ;
2020-03-21 20:55:36 +00:00
describe ( ".getStylesheets" , function ( ) {
it ( "should contain no stylesheets before packages are loaded" , function ( ) {
2018-02-08 05:19:44 +00:00
expect ( packages . getStylesheets ( ) ) . to . be . empty ;
} ) ;
2020-03-21 20:55:36 +00:00
it ( "should return the list of registered stylesheets for loaded packages" , function ( ) {
2018-02-08 05:19:44 +00:00
packages . loadPackages ( ) ;
2019-07-17 09:33:59 +00:00
expect ( packages . getStylesheets ( ) ) . to . deep . equal ( [ "thelounge-package-foo/style.css" ] ) ;
2018-02-08 05:19:44 +00:00
} ) ;
} ) ;
2020-03-21 20:55:36 +00:00
describe ( ".getPackage" , function ( ) {
it ( "should contain no reference to packages before loading them" , function ( ) {
2018-02-08 05:19:44 +00:00
expect ( packages . getPackage ( "thelounge-package-foo" ) ) . to . be . undefined ;
} ) ;
2020-03-21 20:55:36 +00:00
it ( "should return details of a registered package after it was loaded" , function ( ) {
2018-02-08 05:19:44 +00:00
packages . loadPackages ( ) ;
2019-07-17 09:33:59 +00:00
expect ( packages . getPackage ( "thelounge-package-foo" ) ) . to . have . key ( "onServerStart" ) ;
2018-02-08 05:19:44 +00:00
} ) ;
} ) ;
2020-03-21 20:55:36 +00:00
describe ( ".loadPackages" , function ( ) {
it ( "should display report about loading packages" , function ( ) {
2018-02-08 05:19:44 +00:00
// Mock `log.info` to extract its effect into a string
2022-06-19 00:25:21 +00:00
logInfoStub . restore ( ) ;
2018-02-08 05:19:44 +00:00
let stdout = "" ;
2022-06-19 00:25:21 +00:00
logInfoStub = sinon
. stub ( log , "info" )
. callsFake ( TestUtil . sanitizeLog ( ( str ) = > ( stdout += str ) ) ) ;
2018-02-08 05:19:44 +00:00
packages . loadPackages ( ) ;
2019-07-17 09:33:59 +00:00
expect ( stdout ) . to . deep . equal (
2019-11-06 16:16:40 +00:00
"Package thelounge-package-foo vdummy 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"
2019-07-17 09:33:59 +00:00
) ;
2018-02-08 05:19:44 +00:00
} ) ;
} ) ;
} ) ;