Skip to content

Commit

Permalink
test: add test for running as included module
Browse files Browse the repository at this point in the history
This adds a separate test for checking that the server can
start up when included as a module. The needed package.json and
the test itself are copied into a temporary directory, then
the server install is npm pack'd and installed into the temp
directory. Everything I tried within the server directory
ended up with npm complaining or shortcutting things so
that the test either did not work or tested nothing.
  • Loading branch information
tkurki committed Jan 12, 2019
1 parent 01b881b commit 312af75
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test-server-as-include/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "empty",
"version": "1.0.0",
"main": "works-as-include.js",
"dependencies": {
"app-root-path": "^2.1.0"
}
}
24 changes: 24 additions & 0 deletions test-server-as-include/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

TMPDIR=$(mktemp -d)

trap "exit 1" HUP INT PIPE QUIT TERM
trap "rm -rf $TMPDIR" EXIT

BASEDIR=$(dirname $0)

#copy test files to the tmp directory
cp -r ${BASEDIR} $TMPDIR

#pack the server and install from the packed tar file
ORIGINDIR=$(PWD)
PACKEDTARFILE=$(npm pack 2>/dev/null)
cd $TMPDIR/$BASEDIR
npm install
npm install $ORIGINDIR/$PACKEDTARFILE

export SETTINGSDIR=$TMPDIR/settings
mkdir $SETTINGSDIR

node works-as-include.js

12 changes: 12 additions & 0 deletions test-server-as-include/works-as-include.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const appRoot = require('app-root-path')
const SignalKServer = require('signalk-server')
const path = require('path')

const config = {
appPath: appRoot.path,
configPath: process.env.SETTINGSDIR
}

console.log(config)
const server = new SignalKServer({ config });
server.start()

0 comments on commit 312af75

Please sign in to comment.