#!/bin/bash

set -e

DIR=`mktemp -d`
cd $DIR

cat > package.json << EOF
{
  "name": "mjs2cjs-test",
  "version": "0.0.1",
  "main": "dist/index.js"
}
EOF

cat > index.mjs << EOF
import chalk from 'chalk';
import sliceAnsi from 'slice-ansi';

const string = 'The quick brown ' + chalk.red('fox jumped over ') +
	'the lazy ' + chalk.green('dog and then ran away with the unicorn.');

console.log(sliceAnsi(string, 20, 30));
EOF
mjs2cjs index.mjs
cd /
RES=`node $DIR/dist/index.js`
if [ "$RES" != "jumped ove" ]; then
	echo "Result isn't 'jumped ove' but:" >&2
	echo $RES >&2
	exit 1
fi
rm -rf $DIR
