-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathtest-cra-init.sh
executable file
·57 lines (49 loc) · 1.27 KB
/
test-cra-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
set -Eeuo pipefail
assert_contains() {
FILENAME=$1
EXPECTED_CONTENT=$2
if [[ "$(cat $FILENAME)" == *"${EXPECTED_CONTENT}"* ]]; then
return 0
else
echo "Unable to find $EXPECTED_CONTENT in $FILENAME"
return 1
fi
}
# Ensure we're in the correct folder
pushd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null
# Scaffold a new CRA project with storybook and loki
mkdir -p generated
cd generated
rm -rf create-react-app || true
yarn create react-app create-react-app
cd create-react-app
npx -p @storybook/cli sb init
yarn add loki
../../../../node_modules/.bin/loki init
# Ensure modifications has been made
assert_contains "package.json" "$(cat <<-END
"loki": {
"configurations": {
"chrome.laptop": {
"target": "chrome.docker",
"width": 1366,
"height": 768,
"deviceScaleFactor": 1,
"mobile": false
},
"chrome.iphone7": {
"target": "chrome.docker",
"preset": "iPhone 7"
}
}
}
END
)"
# Ensure we can snap stories
yarn build-storybook --quiet
mkdir -p .loki/reference
cp ../../fixtures/chrome_laptop_Welcome_to_Storybook.png ./.loki/reference
yarn loki test laptop --requireReference --storiesFilter Welcome --reactUri file:./storybook-static
# Peace out
popd > /dev/null