-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use nightmare to test custom element stuff
- Loading branch information
1 parent
35637d8
commit ef2a2b3
Showing
22 changed files
with
555 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function equal(a, b, message) { | ||
if (a != b) throw new Error(message || `Expected ${a} to equal ${b}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import * as fs from 'fs'; | ||
import * as http from 'http'; | ||
import { rollup } from 'rollup'; | ||
import virtual from 'rollup-plugin-virtual'; | ||
import Nightmare from 'nightmare'; | ||
import { | ||
showOutput, | ||
loadConfig, | ||
loadSvelte, | ||
env, | ||
setupHtmlEqual, | ||
spaces | ||
} from "../helpers.js"; | ||
|
||
const page = ` | ||
<body> | ||
<main></main> | ||
<script src='/bundle.js'></script> | ||
</body> | ||
`; | ||
|
||
const assert = fs.readFileSync('test/custom-elements/assert.js', 'utf-8'); | ||
|
||
describe.only('custom-elements', () => { | ||
const nightmare = new Nightmare({ show: false }); | ||
|
||
let svelte; | ||
let server; | ||
let bundle; | ||
|
||
before(() => { | ||
svelte = loadSvelte(); | ||
|
||
return new Promise((fulfil) => { | ||
server = http.createServer((req, res) => { | ||
if (req.url === '/') { | ||
res.end(page); | ||
} | ||
|
||
if (req.url === '/bundle.js') { | ||
res.end(bundle); | ||
} | ||
}); | ||
|
||
server.listen('6789', () => { | ||
fulfil(); | ||
}); | ||
}); | ||
}); | ||
|
||
after(() => { | ||
server.close(); | ||
}); | ||
|
||
fs.readdirSync('test/custom-elements/samples').forEach(dir => { | ||
if (dir[0] === '.') return; | ||
|
||
it(dir, () => { | ||
return rollup({ | ||
input: `test/custom-elements/samples/${dir}/test.js`, | ||
plugins: [ | ||
{ | ||
transform(code, id) { | ||
if (id.endsWith('.html')) { | ||
const compiled = svelte.compile(code, { | ||
customElement: true | ||
}); | ||
|
||
return { | ||
code: compiled.code, | ||
map: compiled.map | ||
}; | ||
} | ||
} | ||
}, | ||
|
||
virtual({ | ||
assert | ||
}) | ||
] | ||
}) | ||
.then(bundle => bundle.generate({ format: 'iife', name: 'test' })) | ||
.then(generated => { | ||
bundle = generated.code; | ||
|
||
return nightmare | ||
.goto('http://localhost:6789') | ||
.evaluate(() => { | ||
return test(document.querySelector('main')); | ||
}) | ||
.then(result => { | ||
if (result) console.log(result); | ||
}) | ||
.catch(message => { | ||
throw new Error(message); | ||
}); | ||
}); | ||
|
||
|
||
}); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as assert from 'assert'; | ||
import './main.html'; | ||
|
||
export default function (target) { | ||
target.innerHTML = ` | ||
<custom-element> | ||
<strong>slotted</strong> | ||
</custom-element>`; | ||
|
||
const el = target.querySelector('custom-element'); | ||
|
||
const div = el.shadowRoot.children[0]; | ||
const [slot0, slot1] = div.children; | ||
|
||
assert.equal(slot0.assignedNodes()[1], target.querySelector('strong')); | ||
assert.equal(slot1.assignedNodes().length, 0); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as assert from 'assert'; | ||
import './main.html'; | ||
|
||
export default function (target) { | ||
target.innerHTML = '<custom-element name="world"></custom-element>'; | ||
const el = target.querySelector('custom-element'); | ||
|
||
assert.equal(el.get('name'), 'world'); | ||
|
||
const h1 = el.shadowRoot.querySelector('h1'); | ||
assert.equal(h1.textContent, 'Hello world!'); | ||
} |
4 changes: 2 additions & 2 deletions
4
.../samples/custom-element-styled/input.html → ...tom-elements/samples/new-styled/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<h1>Hello {{name}}!</h1> | ||
<p>styled</p> | ||
|
||
<style> | ||
h1 { | ||
p { | ||
color: red; | ||
} | ||
</style> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as assert from 'assert'; | ||
import CustomElement from './main.html'; | ||
|
||
export default function (target) { | ||
target.innerHTML = '<p>unstyled</p>'; | ||
|
||
new CustomElement({ | ||
target | ||
}); | ||
|
||
const unstyled = target.querySelector('p'); | ||
const styled = target.querySelector('custom-element').shadowRoot.querySelector('p'); | ||
|
||
assert.equal(unstyled.textContent, 'unstyled'); | ||
assert.equal(styled.textContent, 'styled'); | ||
|
||
assert.equal(getComputedStyle(unstyled).color, 'rgb(0, 0, 0)'); | ||
assert.equal(getComputedStyle(styled).color, 'rgb(255, 0, 0)'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Hello {{name}}!</h1> | ||
|
||
<script> | ||
export default { | ||
tag: 'custom-element' | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as assert from 'assert'; | ||
import CustomElement from './main.html'; | ||
|
||
export default function (target) { | ||
new CustomElement({ | ||
target, | ||
data: { | ||
name: 'world' | ||
} | ||
}); | ||
|
||
assert.equal(target.innerHTML, '<custom-element></custom-element>'); | ||
|
||
const el = target.querySelector('custom-element'); | ||
const h1 = el.shadowRoot.querySelector('h1'); | ||
|
||
assert.equal(h1.textContent, 'Hello world!'); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.