@@ -13,66 +13,94 @@ function wait(ms: number) {
1313}
1414
1515describe ( 'Auto-update' , function ( ) {
16- it ( 'auto-update from' , async function ( ) {
17- if ( process . env . TEST_NAME !== 'auto-update-from' ) {
18- // we don't want this test to execute along with all the others under
19- // normal circumstances because it is destructive - it overwrites Compass
20- // itself
21- this . skip ( ) ;
22- }
23-
24- // run the app and wait for it to auto-update
25- console . log ( 'starting compass the first time' ) ;
26- const compass = await init ( 'auto-update from' , { firstRun : true } ) ;
27- const { browser } = compass ;
28- try {
29- await browser . $ ( Selectors . AutoUpdateToast ) . waitForDisplayed ( ) ;
30-
31- if ( process . env . AUTO_UPDATE_UPDATABLE === 'true' ) {
32- const restartButton = browser . $ ( Selectors . AutoUpdateRestartButton ) ;
33- await restartButton . waitForDisplayed ( ) ;
34-
35- // We could click the restart button to apply the update and restart the
36- // app, but restarting the app confuses webdriverio or at least our test
37- // helpers. So we're going to just restart the app manually.
38- await browser . pause ( 1000 ) ;
39- } else {
40- // When auto-update is not supported the toast contains a link to
41- // download
42- const linkElement = browser . $ ( Selectors . AutoUpdateDownloadLink ) ;
43- await linkElement . waitForDisplayed ( ) ;
44- expect ( await linkElement . getAttribute ( 'href' ) ) . to . equal (
45- 'https://www.mongodb.com/try/download/compass?utm_source=compass&utm_medium=product'
46- ) ;
16+ for ( const testName of [ 'auto-update-from' , 'auto-update-to' ] ) {
17+ it ( testName , async function ( ) {
18+ if ( process . env . TEST_NAME !== testName ) {
19+ // we don't want this test to execute along with all the others under
20+ // normal circumstances because it is destructive - it overwrites Compass
21+ // itself
22+ this . skip ( ) ;
4723 }
48- } finally {
49- await browser . screenshot ( screenshotPathName ( 'auto-update-from' ) ) ;
50- await cleanup ( compass ) ;
51- }
5224
53- if ( process . env . AUTO_UPDATE_UPDATABLE === 'true' ) {
54- console . log (
55- 'pause to make sure the app properly exited before starting again'
56- ) ;
57- await wait ( 10_000 ) ;
58-
59- console . log ( 'starting compass a second time' ) ;
60- // run the app again and check that the version changed
61- const compass = await init ( 'auto-update from restart' , {
62- firstRun : false ,
63- } ) ;
25+ // run the app and wait for it to auto-update
26+ console . log ( 'starting compass the first time' ) ;
27+ const compass = await init ( testName , { firstRun : true } ) ;
6428 const { browser } = compass ;
6529 try {
6630 await browser . $ ( Selectors . AutoUpdateToast ) . waitForDisplayed ( ) ;
67- await browser
68- . $ ( Selectors . AutoUpdateReleaseNotesLink )
69- . waitForDisplayed ( ) ;
31+
32+ if ( process . env . AUTO_UPDATE_UPDATABLE === 'true' ) {
33+ const restartButton = browser . $ ( Selectors . AutoUpdateRestartButton ) ;
34+ await restartButton . waitForDisplayed ( ) ;
35+
36+ if ( process . env . EXPECTED_UPDATE_VERSION ) {
37+ expect (
38+ await browser . $ ( Selectors . AutoUpdateToast ) . getText ( )
39+ ) . to . contain (
40+ `Compass is ready to update to ${ process . env . EXPECTED_UPDATE_VERSION } !`
41+ ) ;
42+ }
43+
44+ // We could click the restart button to apply the update and restart the
45+ // app, but restarting the app confuses webdriverio or at least our test
46+ // helpers. So we're going to just restart the app manually.
47+ await browser . pause ( 1000 ) ;
48+ } else {
49+ // When auto-update is not supported the toast contains a link to
50+ // download
51+ const linkElement = browser . $ ( Selectors . AutoUpdateDownloadLink ) ;
52+ await linkElement . waitForDisplayed ( ) ;
53+ expect ( await linkElement . getAttribute ( 'href' ) ) . to . equal (
54+ 'https://www.mongodb.com/try/download/compass?utm_source=compass&utm_medium=product'
55+ ) ;
56+
57+ if ( process . env . EXPECTED_UPDATE_VERSION ) {
58+ expect (
59+ await browser . $ ( Selectors . AutoUpdateToast ) . getText ( )
60+ ) . to . contain (
61+ `Compass ${ process . env . EXPECTED_UPDATE_VERSION } is available`
62+ ) ;
63+ }
64+ }
7065 } finally {
71- await browser . screenshot (
72- screenshotPathName ( 'auto-update-from-restart' )
73- ) ;
66+ await browser . screenshot ( screenshotPathName ( testName ) ) ;
7467 await cleanup ( compass ) ;
7568 }
76- }
77- } ) ;
69+
70+ if ( process . env . AUTO_UPDATE_UPDATABLE === 'true' ) {
71+ console . log (
72+ 'pause to make sure the app properly exited before starting again'
73+ ) ;
74+ await wait ( 10_000 ) ;
75+
76+ console . log ( 'starting compass a second time' ) ;
77+ // run the app again and check that the version changed
78+ const compass = await init ( `${ testName } restart` , {
79+ firstRun : false ,
80+ } ) ;
81+ const { browser } = compass ;
82+ try {
83+ await browser . $ ( Selectors . AutoUpdateToast ) . waitForDisplayed ( ) ;
84+ const releaseNotesLink = browser . $ (
85+ Selectors . AutoUpdateReleaseNotesLink
86+ ) ;
87+ await releaseNotesLink . waitForDisplayed ( ) ;
88+ // for now we only know the new version in the auto-update-to case
89+ if ( process . env . EXPECTED_UPDATE_VERSION ) {
90+ expect (
91+ await browser . $ ( Selectors . AutoUpdateToast ) . getText ( )
92+ ) . to . contain (
93+ `Compass ${ process . env . EXPECTED_UPDATE_VERSION } installed successfully`
94+ ) ;
95+ expect ( await releaseNotesLink . getAttribute ( 'href' ) ) . to . equal (
96+ `https://github.com/mongodb-js/compass/releases/tag/v${ process . env . EXPECTED_UPDATE_VERSION } `
97+ ) ;
98+ }
99+ } finally {
100+ await browser . screenshot ( screenshotPathName ( `${ testName } -restart` ) ) ;
101+ await cleanup ( compass ) ;
102+ }
103+ }
104+ } ) ;
105+ }
78106} ) ;
0 commit comments