-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
8f90ba9
commit 5492655
Showing
4 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var fs = require('fs'); | ||
var join = require('path').join; | ||
var io = require('../../lib'); | ||
|
||
var testHadToCreateFakeModule = false | ||
var fakeModuleLocation = '../socket.io-client' | ||
var socketIOClientMainFilePath = fakeModuleLocation + '/dist/socket.io.js' | ||
|
||
before(function(){ | ||
// set up at fake socket.io-client module sitting at ../.. (sibling to socket.io folder). Emulates being on the same level inside a node_modules folder | ||
// http.Server should ignore the fake module, and use the one in socket.io/node_modules/socket.io-client | ||
try { | ||
fs.mkdirSync(fakeModuleLocation); | ||
testHadToCreateFakeModule = true; | ||
} catch (_) {} | ||
|
||
// load fake package.json | ||
var fakePackageFixture = fs.readFileSync('./test/fixtures/package.json'); | ||
// place fake package.json, if necessary | ||
try { | ||
fs.writeFileSync(fakeModuleLocation + '/package.json', fakePackageFixture, { flag: 'wx' }); | ||
// 'wx' mode fails if the file exists | ||
} catch (_) {} | ||
|
||
try { | ||
fs.mkdirSync(fakeModuleLocation + '/dist'); | ||
} catch (_) {} | ||
|
||
// temporarily put away the real main file, if it exists | ||
try { | ||
fs.renameSync(socketIOClientMainFilePath, socketIOClientMainFilePath + '.temp') | ||
} catch (_) {} | ||
// write in the fake main file | ||
fs.writeFileSync(socketIOClientMainFilePath, '\'im a fake socket.io-client\''); | ||
|
||
io().clearClientCodeCache(); | ||
}) | ||
|
||
after(function(){ | ||
// put the temp file back into place, if it exists | ||
try { | ||
fs.renameSync(socketIOClientMainFilePath + '.temp', socketIOClientMainFilePath) | ||
} catch (_) {} | ||
|
||
if (testHadToCreateFakeModule) { | ||
// delete whole folder | ||
var deleteFolderRecursive = function(path) { | ||
if (fs.existsSync(path)) { | ||
fs.readdirSync(path).forEach((file, index) => { | ||
var curPath = join(path, file); | ||
if (fs.lstatSync(curPath).isDirectory()) { // recurse | ||
deleteFolderRecursive(curPath); | ||
} else { // delete file | ||
fs.unlinkSync(curPath); | ||
} | ||
}); | ||
fs.rmdirSync(path); | ||
} | ||
}; | ||
|
||
deleteFolderRecursive(fakeModuleLocation); | ||
} | ||
|
||
io().clearClientCodeCache(); | ||
}); |
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 @@ | ||
{ | ||
"name": "socket.io-client", | ||
"version": "2.3.0", | ||
"keywords": [ | ||
"this package.json is a fixture for a socket.io test" | ||
], | ||
"main": "./lib/index" | ||
} |
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