#!/bin/sh
# Entry point used by both dh_auto_test and autopkgtest.
#
# Upstream runs its test suite with jest and ts-jest, and neither of them is
# packaged in Debian, so the same test files are compiled with tsc and run by
# the small runner in run-tests.js (see its header for what it implements).
set -e

rm -rf .test-js
tsc --project debian/tests/pkg-js/tsconfig.json

# Run the suite against the files built for the binary package rather than
# against the copy tsc has just written: both come from the same sources, but
# this way the files that are actually shipped are the ones under test.
rm -f .test-js/b+tree.js .test-js/sorted-array.js
rm -rf .test-js/extended
ln -s ../b+tree.js .test-js/b+tree.js
ln -s ../sorted-array.js .test-js/sorted-array.js
ln -s ../extended .test-js/extended

# The suite draws random numbers from the mersenne-twister package, which is
# not in Debian; the stand-in shipped here has the same interface.
mkdir -p .test-js/node_modules
cp -a debian/tests/pkg-js/mersenne-twister .test-js/node_modules/mersenne-twister

node debian/tests/pkg-js/run-tests.js .test-js/test/*.test.js

# Finally check that the built module loads and works through the entry
# points package.json advertises.
node debian/tests/pkg-js/smoke.js
