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

Function serveStaticTest

test/plugins/static.test.js:68–123  ·  view source on GitHub ↗
(done, testDefault, tmpDir, regex, staticFile)

Source from the content-addressed store, hash-verified

66 });
67
68 function serveStaticTest(done, testDefault, tmpDir, regex, staticFile) {
69 var staticContent = '{"content": "abcdefg"}';
70 var staticObj = JSON.parse(staticContent);
71 var testDir = 'public';
72 var testFileName = 'index.json';
73 var routeName = 'GET wildcard';
74 var tmpPath = path.join(__dirname, '../', tmpDir);
75
76 mkdirp(tmpPath, function(err) {
77 assert.ifError(err);
78 DIRS_TO_DELETE.push(tmpPath);
79 var folderPath = path.join(tmpPath, testDir);
80
81 mkdirp(folderPath, function(err2) {
82 assert.ifError(err2);
83
84 DIRS_TO_DELETE.push(folderPath);
85 var file = path.join(folderPath, testFileName);
86
87 fs.writeFile(file, staticContent, function(err3) {
88 assert.ifError(err3);
89 FILES_TO_DELETE.push(file);
90 var p = '/' + testDir + '/' + testFileName;
91 var opts = { directory: tmpPath };
92
93 if (staticFile) {
94 opts.file = p;
95 }
96
97 if (testDefault) {
98 p = '/' + testDir + '/';
99 opts.default = testFileName;
100 routeName += ' with default';
101 }
102
103 SERVER.get(
104 {
105 path: '/' + testDir + '/*',
106 name: routeName
107 },
108 restify.plugins.serveStatic(opts)
109 );
110
111 CLIENT.get(p, function(err4, req, res, obj) {
112 assert.ifError(err4);
113 assert.equal(
114 res.headers['cache-control'],
115 'public, max-age=3600'
116 );
117 assert.deepEqual(obj, staticObj);
118 done();
119 });
120 });
121 });
122 });
123 }
124
125 function testNoAppendPath(done, testDefault, tmpDir, regex, staticFile) {

Callers 1

static.test.jsFile · 0.85

Calls 1

doneFunction · 0.85

Tested by

no test coverage detected