#!/bin/sh
set -e

# Node's ESM resolver ignores NODE_PATH: the modules have to sit in a
# node_modules directory, and the vendored epub.js is not packaged.
mkdir -p node_modules
for m in classnames darkreader eld luaparse mathjax-full pako queue react \
	react-dom typescript; do
	ln -sfn "/usr/share/nodejs/$m" "node_modules/$m"
done
ln -sfn ../epubjs/epub.js node_modules/epubjs

# These import TypeScript sources, and Debian's node is not built with the
# type stripping they need.
tests=$(find test -name '*.test.mjs' | sort |
	grep -vE 'test/common/mobile-view|test/pdf/pdf-sdt-position-mapper|test/pdf/sdt-integration')

# shellcheck disable=SC2086
node --test $tests
