From 15eee9c2e9117e65e9a8515264525f3fb25eca8a Mon Sep 17 00:00:00 2001 From: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> Date: Fri, 8 Dec 2023 20:33:38 -0800 Subject: [PATCH] Trying to fix tests --- .devcontainer/devcontainer.json | 2 +- README.md | 4 +- examples/dynamic-imports/src/routes.js | 2 +- nightwatch.conf.cjs | 2 +- package.json | 2 +- test/cases/01-routing.test.cjs | 74 +++++++++++++------------- 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 87f67dc..88a5bef 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -23,7 +23,7 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [ - 5000 + 5050 ], // Use 'postCreateCommand' to run commands after the container is created. diff --git a/README.md b/README.md index 8e60864..c124844 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,10 @@ cd examples/basic-routing # Build and run (in the folder of a sample) npx rollup -c -npx serve -n -l 5000 dist +npx serve -n -l 5050 dist ```` -The sample will be running at http://localhost:5000 +The sample will be running at http://localhost:5050 ## Starter template diff --git a/examples/dynamic-imports/src/routes.js b/examples/dynamic-imports/src/routes.js index 74b596b..751d8c1 100644 --- a/examples/dynamic-imports/src/routes.js +++ b/examples/dynamic-imports/src/routes.js @@ -39,7 +39,7 @@ export default { .then((component) => { return new Promise((resolve) => { // Wait 5 seconds before returning - setTimeout(() => resolve(component), 5000) + setTimeout(() => resolve(component), 5050) }) }), // Show the loading component while the component is being downloaded diff --git a/nightwatch.conf.cjs b/nightwatch.conf.cjs index 1eea9d1..1ea09cb 100644 --- a/nightwatch.conf.cjs +++ b/nightwatch.conf.cjs @@ -3,7 +3,7 @@ const seleniumHost = process.env.SELENIUM_HOST || '127.0.0.1' const seleniumPort = parseInt(process.env.SELENIUM_PORT || '4444', 10) // Launch URL - where the server is -const launchUrl = process.env.LAUNCH_URL || 'http://localhost:5000' +const launchUrl = process.env.LAUNCH_URL || 'http://localhost:5050' // Increase max listeners to avoid a warning require('events').EventEmitter.defaultMaxListeners = 100 diff --git a/package.json b/package.json index 6fd7851..1f81d2e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "type": "module", "scripts": { "build-test-app": "(cd test/app && npx rollup -c)", - "start-test-app": "npx serve -n -l 5000 test/app/dist", + "start-test-app": "npx serve -n -l 5050 test/app/dist", "eslint": "npx eslint -c .eslintrc.js --ext .js,.svelte,.html .", "lint": "npm run eslint", "nightwatch": "npx nightwatch -e selenium.chrome -c nightwatch.conf.cjs", diff --git a/test/cases/01-routing.test.cjs b/test/cases/01-routing.test.cjs index 7490cfa..7354b7a 100644 --- a/test/cases/01-routing.test.cjs +++ b/test/cases/01-routing.test.cjs @@ -8,18 +8,20 @@ describe(' component', function() { this.timeout(4000) it('renders on the page', (browser) => { + browser.restart() + browser .url(browser.launchUrl) .expect.element('body').to.be.present.before(1000) browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Home!') - - browser.end() + .assert.textContains('h2.routetitle', 'Home!') }) it('current path appears', (browser) => { + browser.restart() + browser .url(browser.launchUrl) .waitForElementVisible('#currentpath') @@ -29,12 +31,14 @@ describe(' component', function() { }) it('selecting route from hash', (browser) => { + browser.restart() + // Main route browser .url(browser.launchUrl + '/#/') .waitForElementVisible('#currentpath') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Home!') + .assert.textContains('h2.routetitle', 'Home!') .expect.element('#currentpath').text.to.equal('/') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('null') @@ -43,7 +47,7 @@ describe(' component', function() { browser .url(browser.launchUrl + '/#/wild') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('null') @@ -52,95 +56,95 @@ describe(' component', function() { browser .url(browser.launchUrl + '/#/hello/svelte') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('{"first":"svelte","last":null}') - - browser.end() }) it('loading page with hash', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/hello/svelte') .waitForElementVisible('#currentpath') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('{"first":"svelte","last":null}') - - browser.end() }) it('refreshing page', (browser) => { + browser.restart() + // /hello/svelte browser .url(browser.launchUrl + '/#/hello/svelte') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('{"first":"svelte","last":null}') - + browser .refresh(() => { browser.waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('{"first":"svelte","last":null}') - - browser.end() }) }) it('catch-all route', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/does/not/exist') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'NotFound') + .assert.textContains('h2.routetitle', 'NotFound') .expect.element('#currentpath').text.to.equal('/does/not/exist') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('{"wild":"does/not/exist"}') - - browser.end() }) it('clicking on link', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/') .waitForElementVisible('ul.navigation-links') .click('.navigation-links a[href="#/hello/svelte"]', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser .expect.element('#nameparams').text.to.equal('Your name is: svelte') - - browser.end() }) }) it('clicking link with children', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/hello/world') .waitForElementVisible('ul.navigation-links') .click('.navigation-links li a b', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Home!') + .assert.textContains('h2.routetitle', 'Home!') .expect.element('#currentpath').text.to.equal('/brand') browser.expect.element('#currentqs').text.to.equal('') browser.expect.element('#currentparams').text.to.equal('null') - - browser.end() }) }) it('back and forward buttons', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/hello/svelte/user') .waitForElementVisible('ul.navigation-links') @@ -166,28 +170,26 @@ describe(' component', function() { browser .waitForElementVisible('#nameparams') .expect.element('#nameparams').text.to.equal('Your name is: svelte') - - browser.end() }) }) }) }) it('push method', (browser) => { + browser.restart() + browser .url(browser.launchUrl + '/#/') .waitForElementVisible('p.navigation-buttons') .click('.navigation-buttons button:nth-of-type(1)', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild/something') browser.expect.element('#currentparams').text.to.equal('{"wild":"something"}') browser.url((url) => { assert.strictEqual(url.value, browser.launchUrl + '/#/wild/something') - - browser.end() }) }) }) @@ -204,7 +206,7 @@ describe(' component', function() { .click('.navigation-buttons button:nth-of-type(2)', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild/something') browser.url((url) => { @@ -228,7 +230,7 @@ describe(' component', function() { .click('.navigation-buttons button:nth-of-type(3)', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild/replaced') browser.url((url) => { @@ -240,7 +242,7 @@ describe(' component', function() { .click('.navigation-buttons button:nth-of-type(2)', () => { browser .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild/something') browser.url((url) => { @@ -260,7 +262,7 @@ describe(' component', function() { browser .url(browser.launchUrl + '/#/hello/svelte?search=query&sort=0') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('search=query&sort=0') @@ -268,7 +270,7 @@ describe(' component', function() { browser .refresh(() => { browser.waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Hi there!') + .assert.textContains('h2.routetitle', 'Hi there!') .expect.element('#currentpath').text.to.equal('/hello/svelte') browser.expect.element('#currentqs').text.to.equal('search=query&sort=0') @@ -318,7 +320,7 @@ describe(' component', function() { // Condition always fails browser.url(browser.launchUrl + '/#/lucky?pass=0') .waitForElementVisible('h2.routetitle') - .assert.containsText('h2.routetitle', 'Wild') + .assert.textContains('h2.routetitle', 'Wild') .expect.element('#currentpath').text.to.equal('/wild/conditions-failed') browser.expect.element('#currentqs').text.to.equal('')