This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I added some "integration tests" where we use electron-hot-loader to require some react components. This has allowed to test that errors thrown by the compiler are as simple as possible. Indeed, when a component requires another component, the errors will be nested and hard to read.
- Loading branch information
Showing
8 changed files
with
106 additions
and
28 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
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,43 @@ | ||
"use strict"; | ||
|
||
const expect = require('expect'); | ||
const describeWithDom = require('describe-with-dom'); | ||
|
||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
|
||
describeWithDom('loadJsx', () => { | ||
|
||
it('should load a JSX file', () => { | ||
const App = require('./views/App.jsx'); | ||
const element = document.createElement('div'); | ||
document.body.appendChild(element); | ||
ReactDOM.render(<App/>, element); | ||
|
||
var window = document.defaultView; | ||
expect(window.document.documentElement.outerHTML).toContain('Hello'); | ||
}); | ||
|
||
it('should throw when a component contains an error', () => { | ||
const exceptionMessage = getExceptionMessage(() => require('./views/ErrorComponent.jsx')); | ||
expect(exceptionMessage) | ||
.toMatch(/^Error compiling [\w\/\-\\]+?ErrorComponent\.jsx: Parse Error: Line 10: Unexpected token }/) | ||
}); | ||
|
||
it('should throw a simple error when a component contains a component which contains an error', () => { | ||
const exceptionMessage = getExceptionMessage(() => require('./views/AppUsingErrorComponent.jsx')); | ||
expect(exceptionMessage) | ||
.toMatch(/^Error compiling [\w\/\-\\]+?ErrorComponent\.jsx: Parse Error: Line 10: Unexpected token }/) | ||
}); | ||
}); | ||
|
||
function getExceptionMessage(executor) { | ||
let message; | ||
try { | ||
executor(); | ||
} catch (e) { | ||
message = e.message; | ||
} | ||
expect(message).toExist('Expected method to throw'); | ||
return message; | ||
} |
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,5 @@ | ||
-u bdd | ||
--recursive ./test-integration/**/*spec.jsx | ||
--full-trace | ||
--reporter spec | ||
--require ./compiler |
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,10 @@ | ||
"use strict"; | ||
|
||
const React = require('react'); | ||
|
||
module.exports = class App extends React.Component { | ||
|
||
render() { | ||
return (<div>Hello</div>) | ||
} | ||
}; |
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,11 @@ | ||
"use strict"; | ||
|
||
const React = require('react'); | ||
const Component = require('./ErrorComponent.jsx'); | ||
|
||
module.exports = class App extends React.Component { | ||
|
||
render() { | ||
return <Component /> | ||
} | ||
}; |
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,11 @@ | ||
"use strict"; | ||
|
||
const React = require('react'); | ||
|
||
// This component intentionnaly contains a parse error | ||
module.exports = class App extends React.Component { | ||
|
||
render() { | ||
return (<div>Hello<div>) | ||
} | ||
}; |