-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Follow redirects Fixes #775 * Follow redirects Fixing lint error * Follow redirects Fix tests * Added redirect test * Fixed lint errors * Skip redirect test in browser as we cannot mock a server * Different test for browser * Fixed browser detection
- Loading branch information
1 parent
c6f1142
commit c3835b2
Showing
3 changed files
with
62 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,57 @@ | ||
import { Jimp as jimp, getTestDir } from '@jimp/test-utils'; | ||
|
||
const fs = require('fs'); | ||
const http = require('http'); | ||
|
||
const imagesDir = getTestDir(__dirname) + '/images'; | ||
|
||
const httpHandler = (req, res) => { | ||
switch (req.method) { | ||
case 'GET': | ||
switch (req.url) { | ||
case '/redirect.png': | ||
res.writeHead(301, { | ||
Location: 'http://localhost:5136/corrected.png' | ||
}); | ||
res.end(); | ||
break; | ||
case '/corrected.png': | ||
res.writeHead(200, { 'Content-Type': 'image/png' }); | ||
res.end(fs.readFileSync(imagesDir + '/pixel.png'), 'binary'); | ||
break; | ||
default: | ||
res.writeHead(404); | ||
res.end('Not a valid test endpoint'); | ||
break; | ||
} | ||
break; | ||
default: | ||
res.writeHead(404); | ||
res.end('Invalid request method'); | ||
break; | ||
} | ||
}; | ||
|
||
describe('redirect', function() { | ||
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { | ||
xit('Not testing redirects in browser'); | ||
} else { | ||
const httpServer = http.createServer(httpHandler); | ||
before(function() { | ||
httpServer.listen(5136); | ||
}); | ||
|
||
it('follows 301 redirect', function(done) { | ||
jimp | ||
.read('http://localhost:5136/redirect.png') | ||
.then(() => { | ||
httpServer.close(); | ||
done(); | ||
}) | ||
.catch(error => { | ||
httpServer.close(); | ||
done(error); | ||
}); | ||
}); | ||
} | ||
}); |