forked from facebook/react-native
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This is the next incremental step to rewrite node-haste. I apologize for the size of this diff but there is really no smaller way to do this. The current architecture passes a single file watcher instance into many classes that each subscribe to file changes. It's really hard to keep track of this. The new implementation reduces the listeners to two (will eventually be just one!) - one in DependencyGraph and one in it's parent's parent's parent (ugh! This doesn't make any sense). This should make it much more straightforward to understand what happens when a file changes. I was able to remove a bunch of tests because jest's watcher takes care of things like ignore patterns. Some of the tests were specifically testing for whether the change events were invoked and they are now much more straightforward as well by manually invoking the `processFileChange` methods. (Relanding a fixed version of D4161662) Reviewed By: kentaromiura Differential Revision: D4194378 fbshipit-source-id: 8c008247a911573f6b5f6b0b374d50d38f62a4f5
- Loading branch information
Showing
20 changed files
with
191 additions
and
741 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 |
---|---|---|
|
@@ -5,32 +5,5 @@ | |
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:facebook/react-native.git" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"jest": { | ||
"setupEnvScriptFile": "jest/setup.js", | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/" | ||
], | ||
"testFileExtensions": [ | ||
"js" | ||
], | ||
"unmockedModulePathPatterns": [ | ||
"source-map" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "node linter.js Examples/", | ||
"start": "./packager.sh" | ||
}, | ||
"dependencies": { | ||
"wordwrap": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"jest-cli": "git://github.com/facebook/jest#0.5.x", | ||
"eslint": "0.9.2" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,25 +15,22 @@ jest.mock('fs'); | |
|
||
const AssetServer = require('../'); | ||
const crypto = require('crypto'); | ||
const {EventEmitter} = require('events'); | ||
const fs = require('fs'); | ||
|
||
const {objectContaining} = jasmine; | ||
|
||
describe('AssetServer', () => { | ||
let fileWatcher; | ||
beforeEach(() => { | ||
const NodeHaste = require('../../node-haste'); | ||
NodeHaste.getAssetDataFromName = require.requireActual('../../node-haste/lib/getAssetDataFromName'); | ||
fileWatcher = new EventEmitter(); | ||
NodeHaste.getAssetDataFromName = | ||
require.requireActual('../../node-haste/lib/getAssetDataFromName'); | ||
}); | ||
|
||
describe('assetServer.get', () => { | ||
it('should work for the simple case', () => { | ||
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -59,7 +56,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -97,7 +93,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png', 'jpg'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -124,7 +119,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -147,7 +141,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -179,7 +172,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root', '/root2'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -208,7 +200,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -241,7 +232,6 @@ describe('AssetServer', () => { | |
const server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['png', 'jpeg'], | ||
fileWatcher, | ||
}); | ||
|
||
fs.__setMockFilesystem({ | ||
|
@@ -271,15 +261,14 @@ describe('AssetServer', () => { | |
}); | ||
|
||
describe('hash:', () => { | ||
let server, fileSystem; | ||
let server, mockFS; | ||
beforeEach(() => { | ||
server = new AssetServer({ | ||
projectRoots: ['/root'], | ||
assetExts: ['jpg'], | ||
fileWatcher, | ||
}); | ||
|
||
fileSystem = { | ||
mockFS = { | ||
'root': { | ||
imgs: { | ||
'[email protected]': 'b1 image', | ||
|
@@ -290,13 +279,13 @@ describe('AssetServer', () => { | |
} | ||
}; | ||
|
||
fs.__setMockFilesystem(fileSystem); | ||
fs.__setMockFilesystem(mockFS); | ||
}); | ||
|
||
it('uses the file contents to build the hash', () => { | ||
const hash = crypto.createHash('md5'); | ||
for (const name in fileSystem.root.imgs) { | ||
hash.update(fileSystem.root.imgs[name]); | ||
for (const name in mockFS.root.imgs) { | ||
hash.update(mockFS.root.imgs[name]); | ||
} | ||
|
||
return server.getAssetData('imgs/b.jpg').then(data => | ||
|
@@ -306,8 +295,8 @@ describe('AssetServer', () => { | |
|
||
it('changes the hash when the passed-in file watcher emits an `all` event', () => { | ||
return server.getAssetData('imgs/b.jpg').then(initialData => { | ||
fileSystem.root.imgs['[email protected]'] = 'updated data'; | ||
fileWatcher.emit('all', 'arbitrary', '/root', 'imgs/[email protected]'); | ||
mockFS.root.imgs['[email protected]'] = 'updated data'; | ||
server.onFileChange('all', '/root/imgs/[email protected]'); | ||
return server.getAssetData('imgs/b.jpg').then(data => | ||
expect(data.hash).not.toEqual(initialData.hash) | ||
); | ||
|
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
Oops, something went wrong.