chore(web): Merge branch 'feat/web/recognizer-input-unit-testing' into feat/web/recognizer-input-unit-testing-2

This commit is contained in:
Joshua A. Horton 2022-07-20 13:27:46 +07:00
commit f1e99340f7
4 changed files with 51 additions and 8 deletions

View file

@ -9,7 +9,6 @@ set -eu
THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")"
cd $(dirname "$THIS_SCRIPT")
FIXTURE_START=" <!-- START: recognizer host fixture -->"
FIXTURE_END=" <!-- END: recognizer host fixture -->"
sed -n "/$FIXTURE_START/, /$FIXTURE_END/{ /$FIXTURE_START/! { /$FIXTURE_END/! p } }" host-fixture.html
# On Windows, `node extractor.js` cannot be directly piped; that requires `node.exe`.
# But that doesn't make sense on other platforms, so... wrapper script.
node extractor.js

View file

@ -0,0 +1,26 @@
var fs = require('fs');
var os = require('os');
const args = process.argv.slice(2);
// args[0] - destination file path. If not provided, the text will be dumped to the console.
fs.readFile('host-fixture.html', 'utf8', function(err, text) {
if(err) {
throw err;
}
let FIXTURE_START = " <!-- START: recognizer host fixture -->" + os.EOL;
let FIXTURE_END = " <!-- END: recognizer host fixture -->" + os.EOL;
let startIndex = text.indexOf(FIXTURE_START);
let endIndex = text.indexOf(FIXTURE_END) + FIXTURE_END.length;
let desiredText = text.substring(startIndex, endIndex);
if(args[0]) {
fs.writeFileSync(args[0], desiredText);
} else {
console.log(desiredText);
}
});

View file

@ -34,12 +34,9 @@ build_recorder_page ( ) {
cp ../host-fixture/gestureHost.css build/gestureHost.css
FIXTURE=`$FIXTURE_SCRIPT`
FIXTURE_TARGET="<!--INSERT_FIXTURE-->"
# Thanks to https://stackoverflow.com/a/10107668 for this tidbit.
# Searches for FIXTURE_TARGET above and replaces it with the actual fixture!
awk -v r="$FIXTURE" "{gsub(/$FIXTURE_TARGET/,r)}1" src/index.html > build/index.html
node update-index.js build/index.html
}
FIXTURE_SCRIPT=../host-fixture/extract-fixture.sh

View file

@ -0,0 +1,21 @@
var fs = require('fs');
var os = require('os');
var child_process = require('child_process');
const args = process.argv.slice(2);
// args[0] - destination file path. If not provided, the text will be dumped to the console.
fs.readFile('src/index.html', 'utf8', function(err, text) {
if(err) {
throw err;
}
// Runs the fixture-extractor script, receives the fixture's raw HTML.
let buf = child_process.execSync("node extractor.js", {cwd: "../host-fixture", windowsHide: true, shell: true}).toString();
let INSERTION_POINT = " <!--INSERT_FIXTURE-->" + os.EOL;
text = text.replace(INSERTION_POINT, buf);
fs.writeFileSync(args[0], text);
});