Skip to content

Commit 66ca232

Browse files
committed
Simplify test setup
* Remove require hooks and use plugin option instead * Switched to centralized CLI test harness
1 parent d0990c2 commit 66ca232

File tree

9 files changed

+33
-94
lines changed

9 files changed

+33
-94
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"eslint": "^4.4.1",
2424
"eslint-config-fnd": "^1.2.0",
2525
"json-diff": "^0.5.2",
26-
"node-hook": "^1.0.0",
2726
"release-util-fnd": "^1.0.5"
2827
}
2928
}

test/hooks.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/local.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/run

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,36 @@
11
#!/usr/bin/env bash
2-
3-
set -e
2+
set -euo pipefail
43

54
root=`dirname "$0"`
6-
root=`realpath "$root/.."`
7-
. "$root/test/local.sh"
8-
9-
function begin {
10-
test_dir="${1:?}"
11-
echo; echo `basename "$test_dir"`
12-
pushd "$test_dir" > /dev/null
13-
}
14-
15-
function end {
16-
bundles_dir=${1:-"./dist"}
17-
rm -r "$bundles_dir"
18-
popd > /dev/null
19-
}
20-
21-
function assert_identical {
22-
actual="${1:?}"
23-
expected="${2:?}"
24-
# NB: `git diff` provides colorization (dependent on configuration)
25-
git diff --no-index "$expected" "$actual" || \
26-
fail "files \`$actual\` and \`$expected\` are not identical"
27-
}
28-
29-
function assert_identical_json {
30-
actual="${1:?}"
31-
expected="${2:?}"
32-
json-diff "$expected" "$actual" || \
33-
fail "files \`$actual\` and \`$expected\` are not identical"
34-
}
5+
root=`realpath "$root"`
356

36-
function assert_manifest {
37-
asset_path="${1:?}"
38-
uri="${2:?}"
39-
manifest_path=${3:-"./dist/manifest.json"}
7+
. "$root/../node_modules/faucet-pipeline/test/cli_harness.sh"
408

41-
json="\"$asset_path\":\"$uri\""
42-
grep -q "$json" "$manifest_path" || \
43-
fail "manifest \`$manifest_path\` does not contain \`$json\`"
44-
}
45-
46-
function assert_missing {
47-
filepath="${1:?}"
48-
if [ -f "$filepath" ]; then
49-
fail "file \`$filepath\` should not exist"
50-
else
51-
true
52-
fi
53-
}
54-
55-
function fail {
56-
msg="${1:?}"
57-
echo; echo "FAILURE: $msg"
58-
false
59-
}
60-
61-
cd "$root/test"
62-
63-
begin "./test_basic"
9+
begin "$root/test_basic"
6410
faucet
6511
assert_identical "./dist/test.txt" "./src/test.txt"
6612
assert_identical "./dist/inner/test2.txt" "./src/inner/test2.txt"
6713
end
6814

69-
begin "./test_fingerprint"
15+
begin "$root/test_fingerprint"
7016
faucet --fingerprint
7117
assert_identical "./dist/test-e59ff97941044f85df5297e1c302d260.txt" "./src/test.txt"
72-
assert_identical_json "./dist/manifest.json" "./expected.json"
18+
assert_json "./dist/manifest.json" "./expected.json"
7319
end
7420

75-
begin "./test_manifest_base_uri"
21+
begin "$root/test_manifest_base_uri"
7622
faucet --fingerprint
77-
assert_identical_json "./dist/manifest.json" "./expected.json"
23+
assert_json "./dist/manifest.json" "./expected.json"
7824
end
7925

80-
begin "./test_single"
26+
begin "$root/test_single"
8127
faucet
8228
assert_identical "./dist/dist.txt" "./src.txt"
8329
end
8430

85-
begin "./test_key_config"
31+
begin "$root/test_key_config"
8632
faucet --fingerprint
87-
assert_identical_json "./dist/manifest.json" "./expected.json"
33+
assert_json "./dist/manifest.json" "./expected.json"
8834
end
35+
36+
echo; echo "SUCCESS: all tests passed"

test/test_basic/faucet.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"use strict";
2+
let path = require("path");
23

34
module.exports = {
45
static: [{
56
source: "./src",
67
target: "./dist"
7-
}]
8+
}],
9+
plugins: {
10+
"static": path.resolve("../..")
11+
}
812
};

test/test_fingerprint/faucet.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2+
let path = require("path");
23

34
module.exports = {
45
static: [{
@@ -7,5 +8,8 @@ module.exports = {
78
}],
89
manifest: {
910
file: "./dist/manifest.json"
11+
},
12+
plugins: {
13+
"static": path.resolve("../..")
1014
}
1115
};

test/test_key_config/faucet.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ module.exports = {
99
manifest: {
1010
file: "./dist/manifest.json",
1111
key: (f, targetDir) => path.relative(targetDir, f)
12+
},
13+
plugins: {
14+
"static": path.resolve("../..")
1215
}
1316
};

test/test_manifest_base_uri/faucet.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ module.exports = {
99
manifest: {
1010
file: "./dist/manifest.json",
1111
value: f => `/assets/${path.relative("./dist", f)}`
12+
},
13+
plugins: {
14+
"static": path.resolve("../..")
1215
}
1316
};

test/test_single/faucet.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"use strict";
2+
let path = require("path");
23

34
module.exports = {
45
static: [{
56
source: "./src.txt",
67
target: "./dist/dist.txt"
7-
}]
8+
}],
9+
plugins: {
10+
"static": path.resolve("../..")
11+
}
812
};

0 commit comments

Comments
 (0)