Skip to content

Commit

Permalink
Trying to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ItalyPaleAle committed Dec 9, 2023
1 parent ff99e63 commit 15eee9c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic-imports/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nightwatch.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
74 changes: 38 additions & 36 deletions test/cases/01-routing.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ describe('<Router> 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')
Expand All @@ -29,12 +31,14 @@ describe('<Router> 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')
Expand All @@ -43,7 +47,7 @@ describe('<Router> 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')
Expand All @@ -52,95 +56,95 @@ describe('<Router> 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')
Expand All @@ -166,28 +170,26 @@ describe('<Router> 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()
})
})
})
Expand All @@ -204,7 +206,7 @@ describe('<Router> 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) => {
Expand All @@ -228,7 +230,7 @@ describe('<Router> 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) => {
Expand All @@ -240,7 +242,7 @@ describe('<Router> 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) => {
Expand All @@ -260,15 +262,15 @@ describe('<Router> 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')

// Refresh the page
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')

Expand Down Expand Up @@ -318,7 +320,7 @@ describe('<Router> 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('')

Expand Down

0 comments on commit 15eee9c

Please sign in to comment.