MCPcopy Index your code
hub / github.com/restify/node-restify / simpleTests

Function simpleTests

test/plugins/staticFiles.test.js:47–78  ·  view source on GitHub ↗
(endpoint, filePath, contentType, done)

Source from the content-addressed store, hash-verified

45
46 var STATIC_FILES_PATH = __dirname + '/testStaticFiles';
47 function simpleTests(endpoint, filePath, contentType, done) {
48 var ENDPOINT = endpoint;
49 var fileSuffixPath = filePath;
50 var requestPath = path.join(ENDPOINT, fileSuffixPath);
51 var fileOnDisk = path.join(STATIC_FILES_PATH, fileSuffixPath);
52 if (fileSuffixPath.endsWith('/')) {
53 fileOnDisk = path.join(fileOnDisk, 'index.html');
54 }
55 var fileContent = fs.readFileSync(fileOnDisk, 'utf8');
56 var fileStat = fs.statSync(fileOnDisk);
57 SERVER.get(
58 ENDPOINT + '/*',
59 restify.plugins.serveStaticFiles(path.resolve(STATIC_FILES_PATH))
60 );
61
62 CLIENT.get(encodeURI(requestPath), function(err, req, res, obj) {
63 assert.ifError(err);
64 assert.equal(fileContent, obj);
65 // Verify headers
66 assert.equal(res.headers['cache-control'], 'public, max-age=0');
67 assert.equal(
68 res.headers['content-type'],
69 contentType //'text/html; charset=UTF-8'
70 );
71 assert.exists(res.headers.etag);
72 assert.equal(
73 res.headers['last-modified'],
74 fileStat.mtime.toUTCString()
75 );
76 done();
77 });
78 }
79 it('serve static file', function(done) {
80 simpleTests('/public', 'index.html', 'text/html; charset=UTF-8', done);
81 });

Callers 1

Calls 1

doneFunction · 0.85

Tested by

no test coverage detected