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.
Merge pull request #8 from geowarin/fix-windows-paths
Fix windows paths
- Loading branch information
Showing
8 changed files
with
124 additions
and
22 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,96 @@ | ||
/* global describe,it,before,after */ | ||
'use strict'; | ||
|
||
const expect = require('expect'); | ||
var jsdom = require('jsdom-global'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const temp = require('temp').track(); | ||
|
||
let rootDir; | ||
let cleanup; | ||
|
||
describe('loadJsx', function () { | ||
this.timeout(10000); | ||
|
||
before(() => { | ||
cleanup = jsdom(); | ||
const electronHot = require('../src/index'); | ||
electronHot.install(); | ||
|
||
rootDir = temp.mkdirSync('electron-hot'); | ||
createTempJsx('./views/index.jsx'); | ||
createTempJsx('./views/App.jsx'); | ||
|
||
// Strange bug on OSX | ||
const cwd = os.platform() === 'darwin' ? '/private' + rootDir : rootDir; | ||
electronHot.watchJsx(['**/*.jsx'], {cwd: cwd, delay: 0}); | ||
}); | ||
|
||
it('should hot reload JSX files', (done) => { | ||
const indexJsx = path.join(rootDir, 'index.jsx'); | ||
const appJsx = path.join(rootDir, 'App.jsx'); | ||
|
||
require(indexJsx); | ||
|
||
// our html contains Hello | ||
expect(getHtmlBody()).toContain('Hello'); | ||
|
||
doLater(() => changeFile(appJsx, content => content.replace('Hello', 'Hi'))) | ||
.then(() => waitFor(() => getHtmlBody().match('Hi'))) | ||
.then(done); | ||
}); | ||
|
||
after(() => { | ||
cleanup(); | ||
delete require.extensions['.jsx']; | ||
temp.cleanupSync(); | ||
}); | ||
}); | ||
|
||
function waitFor (condition) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
const interval = setInterval(() => { | ||
if (condition()) { | ||
clearInterval(interval); | ||
resolve(); | ||
} | ||
}, 100); | ||
}, 0); | ||
}); | ||
} | ||
|
||
function doLater (thing) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
thing(); | ||
resolve(); | ||
}, 500); | ||
}); | ||
} | ||
|
||
function changeFile (filePath, transform) { | ||
let content = fs.readFileSync(filePath).toString(); | ||
content = transform(content); | ||
fs.writeFileSync(filePath, content); | ||
} | ||
|
||
function getHtmlBody () { | ||
return document.defaultView.document.documentElement.outerHTML; | ||
} | ||
|
||
function createTempJsx (source) { | ||
let content = fs.readFileSync(require.resolve(source)).toString(); | ||
|
||
const reactPath = require.resolve('react').replace(/\\/g, '/'); | ||
content = content.replace("require('react')", `require('${reactPath}')`); | ||
|
||
const reactDOMPath = require.resolve('react-dom').replace(/\\/g, '/'); | ||
content = content.replace("require('react-dom')", `require('${reactDOMPath}')`); | ||
|
||
const sourceFileName = path.basename(source); | ||
fs.writeFileSync(path.join(rootDir, sourceFileName), content); | ||
} | ||
|
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,4 @@ | ||
-u bdd | ||
--recursive ./test-integration/**/*spec.jsx | ||
--recursive ./test-integration/**/*spec.js | ||
--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,9 @@ | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
|
||
console.debug = () => {}; | ||
|
||
const App = require('./App.jsx'); | ||
const element = document.createElement('div'); | ||
document.body.appendChild(element); | ||
ReactDOM.render(<App/>, element); |
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.