git.iko.soy/typeable/elm-ui
on master help sign in
revive sauce-labs testing in a much more convenient way
c0eff78Matthew Griffith
tests/automation/publish-file.sh+17−9
@@ -1,8 +1,8 @@
1−These env variables need to be set before running this script
1+# These env variables need to be set before running this script
2# FILE="test.html"
2# FILE="test.html"
3# BUILD="1.1.0"
3# BUILD="1.1.0"
4# NAME="development"
4# NAME="development"
5−DIRECTORY='./tmp/elm-ui-testing'
5+DIRECTORY='elm-ui-testing'
6
6
7# Check to see if the repo is already cloned locally
7# Check to see if the repo is already cloned locally
8cd tmp
8cd tmp
@@ -11,11 +11,19 @@ if [ ! -d "$DIRECTORY" ]; then
11else
11else
12 git pull
12 git pull
13fi
13fi
14−mkdir -p "elm-ui-testing/public/tests/$BUILD/$NAME/"
14+mkdir -p "$DIRECTORY/public/tests/$BUILD/$NAME/"
15−cp "$FILE" "elm-ui-testing/public/tests/$BUILD/$NAME/index.html"
15+cp "$FILE" "$DIRECTORY/public/tests/$BUILD/$NAME/index.html"
16−cd elm-ui-testing
16+if [ -z "$(git status --porcelain)" ]; then
17+ # Working directory clean
18+ echo "No changes need for $BUILD -> $NAME"
19+else
20+ cd "$DIRECTORY"
21+ # Uncommitted changes
17−git add .
22+ git add .
18−git commit -m "Elm UI test for $NAME on $BUILD"
23+ git commit -m "Elm UI test for $NAME on $BUILD"
19−git push origin master
24+ git push origin master
25+
26+ echo "Files published for for $BUILD -> $NAME"
27+fi
28+
20
29
21−echo "done"
tests/automation/run.js+52−34
@@ -13,6 +13,7 @@ program.option('-s, --sauce', 'run tests on sauce labs')
13 .option('--firefox', 'run only firefox tests')
13 .option('--firefox', 'run only firefox tests')
14 .option('--build [value]', 'Set build number for sauce labs')
14 .option('--build [value]', 'Set build number for sauce labs')
15 .option('--name [value]', 'Set run name for sauce labs')
15 .option('--name [value]', 'Set run name for sauce labs')
16+ .option('--verbose', 'Print out all test results')
16 .parse(process.argv)
17 .parse(process.argv)
17
18
18
19
@@ -26,10 +27,6 @@ const windows = [
26 browser: "firefox"
27 browser: "firefox"
27 , browserVersion: "latest"
28 , browserVersion: "latest"
28 },
29 },
29− {
30− browser: "safari"
31− , browserVersion: "latest"
32− },
33 {
30 {
34 browser: "MicrosoftEdge"
31 browser: "MicrosoftEdge"
35 , browserVersion: "latest"
32 , browserVersion: "latest"
@@ -73,16 +70,15 @@ function prepare_all_envs(config) {
73 })
70 })
74 }
71 }
75
72
76− for (i = 0; i < osx.length; i++) {
73+ // for (i = 0; i < osx.length; i++) {
77− envs.push({
74+ // envs.push({
78− browser: osx[i].browser,
75+ // browser: osx[i].browser,
79− browserVersion: osx[i].browserVersion,
76+ // browserVersion: osx[i].browserVersion,
80− platform: "macOS 10.14",
77+ // platform: "macOS 10.14",
81− build: config.build,
78+ // build: config.build,
82− name: config.name
79+ // name: config.name
83− })
80+ // })
84− }
81+ // }
85−
86
82
87 return envs
83 return envs
88}
84}
@@ -103,7 +99,7 @@ function prepare_sauce_driver(env) {
103 const username = process.env.SAUCE_USERNAME;
99 const username = process.env.SAUCE_USERNAME;
104 const accessKey = process.env.SAUCE_ACCESS_KEY;
100 const accessKey = process.env.SAUCE_ACCESS_KEY;
105
101
106− driver = new webdriver.Builder().withCapabilities({
102+ driver = new Builder().withCapabilities({
107 'browserName': env.browser,
103 'browserName': env.browser,
108 'platformName': env.platform,
104 'platformName': env.platform,
109 'browserVersion': env.browserVersion,
105 'browserVersion': env.browserVersion,
@@ -133,11 +129,10 @@ async function prepare_local_driver(env) {
133}
129}
134
130
135async function run_test(driver, url) {
131async function run_test(driver, url) {
136−
137 var results = null
132 var results = null
138 try {
133 try {
139 await driver.get(url);
134 await driver.get(url);
140− await driver.wait(until.titleIs('tests finished'), 60000);
135+ await driver.wait(until.titleIs('tests finished'), 120 * 1000);
141 results = await driver.executeScript("return test_results")
136 results = await driver.executeScript("return test_results")
142 } finally {
137 } finally {
143 await driver.quit();
138 await driver.quit();
@@ -169,7 +164,6 @@ async function run_test(driver, url) {
169 throw ("A Build and a Name must be specified.");
164 throw ("A Build and a Name must be specified.");
170 }
165 }
171
166
172−
173 var results = []
167 var results = []
174
168
175 // Publish to netlify
169 // Publish to netlify
@@ -181,15 +175,22 @@ async function run_test(driver, url) {
181 }
175 }
182 })
176 })
183 var url = `http://elm-ui-testing.netlify.com/tests/${program.build}/${program.name}/`
177 var url = `http://elm-ui-testing.netlify.com/tests/${program.build}/${program.name}/`
184− console.log(`Running sauce labs test ${url}`)
178+ console.log(`Running sauce labs test:`)
185−
179+ console.log(` ${url}`)
186
180
187 const envs = prepare_all_envs({ build: build, name: name })
181 const envs = prepare_all_envs({ build: build, name: name })
182+ var test_runs = []
183+ var test_labels = []
188 for (i = 0; i < envs.length; i++) {
184 for (i = 0; i < envs.length; i++) {
189 var driver = prepare_sauce_driver(envs[i])
185 var driver = prepare_sauce_driver(envs[i])
190− results.push(await run_test(driver, url))
186+ test_runs.push(run_test(driver, url))
191− }
187+ test_labels.push(envs[i])
192
188
189+ }
190+ var results = await Promise.all(test_runs)
191+ for (i = 0; i < results.length; i++) {
192+ print_results(renderEnvName(test_labels[i]), results[i]);
193+ }
193
194
194 } else {
195 } else {
195
196
@@ -198,42 +199,59 @@ async function run_test(driver, url) {
198 console.log("Running locally on Chrome...")
199 console.log("Running locally on Chrome...")
199 const driver = await prepare_local_driver(osx.chrome)
200 const driver = await prepare_local_driver(osx.chrome)
200 var results = await run_test(driver, "file://" + path.resolve('./tmp/test.html'))
201 var results = await run_test(driver, "file://" + path.resolve('./tmp/test.html'))
201− print_results(results);
202+ print_results("Local Chrome", results);
202 }
203 }
203 if (program.firefox) {
204 if (program.firefox) {
204 console.log("Running locally on Firefox...")
205 console.log("Running locally on Firefox...")
205 const driver = await prepare_local_driver(osx.firefox)
206 const driver = await prepare_local_driver(osx.firefox)
206 var results = await run_test(driver, "file://" + path.resolve('./tmp/test.html'))
207 var results = await run_test(driver, "file://" + path.resolve('./tmp/test.html'))
207− print_results(results);
208+ print_results("Local Firefox", results);
208 }
209 }
209
210
210 }
211 }
211})();
212})();
212
213
214+function renderEnvName(env) {
215+ return `${env.platform}, ${env.browser} ${env.browserVersion}`
216+}
213
217
214−function print_results(results) {
218+function print_results(label, results) {
215− var passed = 0
219+ var total_passed = 0
216− var failed = 0
220+ var total_failed = 0
217 var i;
221 var i;
222+ if (program.verbose) {
223+ console.log(label)
224+ }
218 for (i = 0; i < results.length; i++) {
225 for (i = 0; i < results.length; i++) {
219− passed = 0
226+ var passed = 0
220− failed = 0
227+ var failed = 0
221− console.log(results[i].label)
222 for (j = 0; j < results[i].results.length; j++) {
228 for (j = 0; j < results[i].results.length; j++) {
223 if (results[i].results[j][1] == null) {
229 if (results[i].results[j][1] == null) {
224 passed = passed + 1
230 passed = passed + 1
225 } else {
231 } else {
232+ if (failed == 0) {
233+ if (!program.verbose) {
234+ console.log(label)
235+ }
236+ console.log(results[i].label)
237+ }
226 failed = failed + 1
238 failed = failed + 1
227 console.log(" " + chalk.red("fail") + " -> " + results[i].results[j][0])
239 console.log(" " + chalk.red("fail") + " -> " + results[i].results[j][0])
228 console.log(" " + results[i].results[j][1].description)
240 console.log(" " + results[i].results[j][1].description)
229 }
241 }
230 }
242 }
243+ total_passed = total_passed + passed
244+ total_failed = total_failed + failed
245+
231− if (failed == 0) {
246+ if (failed != 0) {
232− console.log(chalk.green(` All ${passed} tests passed`))
233− } else {
234 console.log(chalk.green(` ${passed} tests passed`))
247 console.log(chalk.green(` ${passed} tests passed`))
235 console.log(chalk.red(` ${failed} tests failed`))
248 console.log(chalk.red(` ${failed} tests failed`))
249+ console.log()
250+ } else if (program.verbose) {
251+ console.log(results[i].label + chalk.green(` ${passed} tests passed`))
236 }
252 }
237− console.log()
253+ }
254+ if (total_failed == 0) {
255+ console.log(`${label} -> ` + chalk.green(`All ${total_passed} tests passed`))
238 }
256 }
239}
257}