-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ba5bd6
commit 8fe8345
Showing
20 changed files
with
163 additions
and
148 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
File renamed without changes.
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
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
This file was deleted.
Oops, something went wrong.
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,111 @@ | ||
import { document } from 'global'; | ||
import { unregister, tag2 } from 'riot'; | ||
import { render } from './rendering'; | ||
import { asCompiledCode } from './compileStageFunctions'; | ||
|
||
const rootElement = document.createElement('div'); | ||
rootElement.id = 'root'; | ||
document.body = document.createElement('body'); | ||
document.body.appendChild(rootElement); | ||
|
||
beforeEach(() => { | ||
unregister('#root'); | ||
rootElement.dataset.is = 'root'; | ||
}); | ||
|
||
describe('render a riot element', () => { | ||
it('should not work with nothing', () => { | ||
expect(render(null)).toBe(false); | ||
|
||
expect(rootElement.innerHTML).toEqual(''); | ||
}); | ||
|
||
it('can work with some text', () => { | ||
expect(render({ tags: ['<div><p>some tests</p></div>'] })).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toEqual('<div><p>some tests</p></div>'); | ||
}); | ||
|
||
it('can work with raw code', () => { | ||
expect(render("riot.tag2('root', '<div>raw code</div>', '', '', () => {})")).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toEqual('<div>raw code</div>'); | ||
}); | ||
|
||
it('can work with compiled code', () => { | ||
expect(render([{}])).toBe(true); | ||
// does only work in true mode, and not in jest mode | ||
}); | ||
|
||
it('will be possible to compile a template before rendering it', () => { | ||
const compiledTemplate = asCompiledCode('<template><div>raw code</div></template>'); | ||
|
||
expect(compiledTemplate).toEqual( | ||
"tag2('template', '<div>raw code</div>', '', '', function(opts) {\n});" | ||
); | ||
}); | ||
|
||
it('works with a json consisting in a tagName and opts', () => { | ||
tag2('hello', '<p>Hello { opts.suffix }</p>', '', '', () => {}); | ||
|
||
expect(render({ tagName: 'hello', opts: { suffix: 'World' } })).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toEqual('<p>Hello World</p>'); | ||
}); | ||
|
||
it('can nest several tags', () => { | ||
expect( | ||
render({ | ||
tags: [ | ||
'<Tag1><div>Inside tag1:<ul><li><Tag2><yield/></Tag2></li></ul></div></Tag1>', | ||
'<Tag2><div>Inside tag2:<ul><li><Tag3><yield/></Tag3></li></ul></div></Tag2>', | ||
'<Tag3><div>Inside tag3:<ul><li><Tag4><yield/></Tag4></li></ul></div></Tag3>', | ||
'<Tag4><div>Inside tag4:<ul><li><Tag5><yield/></Tag5></li></ul></div></Tag4>', | ||
'<Tag5><div>Inside tag5:<ul><li><yield/></li></ul></div></Tag5>', | ||
], | ||
template: '<Matriochka><div><Tag1>Content</Tag1></div></Matriochka>', | ||
}) | ||
).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
it('can template some vars', () => { | ||
expect( | ||
render({ | ||
tags: [ | ||
{ | ||
content: | ||
"<SimpleTest><div>simple test ({opts.test || 'without parameter'}). Oh, by the way ({opts.riotValue || '... well, nothing'})</div></SimpleTest>", | ||
boundAs: 'mustBeUniquePlease', | ||
}, | ||
], | ||
template: | ||
'<SimpleTest test={ "with a parameter" } value={"value is mapped to riotValue"}></SimpleTest>', | ||
}) | ||
).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
it('can accept a constructor', () => { | ||
expect( | ||
render({ | ||
tags: [ | ||
{ | ||
content: | ||
"<SimpleTest><div>HACKED : {opts.hacked} ; simple test ({opts.test || 'without parameter'}). Oh, by the way ({opts.riotValue || '... well, nothing'})</div></SimpleTest>", | ||
boundAs: 'mustBeUniquePlease', | ||
}, | ||
], | ||
template: | ||
'<SimpleTest hacked={hacked} test={ "with a parameter" } value={"value is mapped to riotValue"}></SimpleTest>', | ||
tagConstructor: function tagConstructor() { | ||
this.hacked = true; | ||
}, | ||
}) | ||
).toBe(true); | ||
|
||
expect(rootElement.innerHTML).toMatchSnapshot(); | ||
}); | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
...preview/rendering/compiledButUnmounted.js → ...preview/rendering/compiledButUnmounted.ts
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,5 +1,5 @@ | ||
import { mount } from 'riot'; | ||
|
||
export default function renderCompiledButUnmounted(component) { | ||
export default function renderCompiledButUnmounted(component: any) { | ||
mount('root', component.tagName, component.opts || {}); | ||
} |
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
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
app/riot/src/server/framework-preset-riot.js → app/riot/src/server/framework-preset-riot.ts
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
File renamed without changes.
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,8 @@ | ||
declare module '@storybook/core/*'; | ||
declare module 'global'; | ||
declare module 'riot-compiler'; | ||
declare module 'riot' { | ||
const tag2: Function; | ||
const mount: Function; | ||
const unregister: Function; | ||
} |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["jest", "webpack-env"] | ||
} | ||
} |
Oops, something went wrong.