#!/bin/sh
# autopkgtest: run the upstream test suites against the installed package.
#
# The suites are ES modules which import the components as ES modules and
# reach into the per component esm/ trees by relative path.  Those trees are
# built at package build time and live in /usr/share/nodejs/@fluent/*, so they
# are symlinked next to the suites copied here by debian/tests/pkg-js/files.
set -e

for c in fluent-bundle fluent-syntax fluent-dedent fluent-langneg \
	fluent-sequence fluent-dom fluent-react; do
	[ -e "$c/esm" ] && continue
	ln -sfn "/usr/share/nodejs/@fluent/${c#fluent-}/esm" "$c/esm"
done

# The suites also import cached-iterable, sinon, jsdom and react by bare name.
export NODE_PATH=/usr/share/nodejs

# These use mocha's tdd interface, as the upstream .mocharc.yaml sets; that
# file is copied here as well, but do not rely on it being found.
#
# temporal_test.js needs temporal-polyfill, which is not in Debian.
for c in fluent-bundle fluent-syntax fluent-dedent fluent-langneg fluent-sequence; do
	echo "### $c"
	(cd "$c" && mocha --ui tdd --ignore test/temporal_test.js 'test/*_test.js')
done

# @fluent/dom's suite additionally needs its own bootstrap.
echo "### fluent-dom"
(cd fluent-dom && mocha --ui tdd --require ./test/index.js 'test/*_test.js')

# @fluent/react's suite runs under jest with the jsdom environment.
echo "### fluent-react"
(cd fluent-react && jest)
