123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 'use strict';
- const fs = require('fs');
- const path = require('path');
- const eol = require('eol');
- module.exports = {
- 'a.txt': {
- code: 200,
- type: 'text/plain',
- body: 'A!!!\n',
- },
- 'b.txt': {
- code: 200,
- type: 'text/plain',
- body: 'B!!!\n',
- },
- 'c.js': {
- code: 200,
- type: 'application/javascript',
- body: 'console.log(\'C!!!\');\n',
- },
- 'd.js': {
- code: 200,
- type: 'application/javascript',
- body: 'd.js\n',
- },
- 'e.js': {
- code: 200,
- type: 'application/javascript',
- body: 'console.log(\'π!!!\');\n',
- },
- 'subdir/e.html': {
- code: 200,
- type: 'text/html',
- body: '<b>e!!</b>\n',
- },
- // test for defaultExt
- 'subdir/e?foo=bar': {
- code: 200,
- type: 'text/html',
- body: '<b>e!!</b>\n',
- },
- // test for defaultExt with noisy query param
- 'subdir/e?foo=bar.ext': {
- code: 200,
- type: 'text/html',
- body: '<b>e!!</b>\n',
- },
- 'subdir/index.html': {
- code: 200,
- type: 'text/html',
- body: 'index!!!\n',
- },
- subdir: {
- code: 302,
- location: 'subdir/',
- },
- 'subdir?foo=bar': {
- code: 302,
- location: 'subdir/?foo=bar',
- },
- // test for url-encoded paths
- '%E4%B8%AD%E6%96%87': { // '/中文'
- code: 302,
- location: '%E4%B8%AD%E6%96%87/',
- },
- '%E4%B8%AD%E6%96%87?%E5%A4%AB=%E5%B7%B4': { // '中文?夫=巴'
- code: 302,
- location: '%E4%B8%AD%E6%96%87/?%E5%A4%AB=%E5%B7%B4',
- },
- 'subdir/': {
- code: 200,
- type: 'text/html',
- body: 'index!!!\n',
- },
- 404: {
- code: 200,
- type: 'text/html',
- body: '<h1>404</h1>\n',
- },
- 'something-non-existant': {
- code: 404,
- type: 'text/html',
- body: '<h1>404</h1>\n',
- },
- 'compress/foo.js': {
- code: 200,
- file: 'compress/foo.js.gz',
- headers: { 'accept-encoding': 'compress, gzip' },
- body: fs.readFileSync(path.join(__dirname, '../', 'public', 'compress', 'foo.js.gz'), 'utf8'),
- },
- // no accept-encoding of gzip, so serve regular file
- 'compress/foo_2.js': {
- code: 200,
- file: 'compress/foo_2.js',
- },
- 'emptyDir/': {
- code: 404,
- body: '<h1>404</h1>\n',
- },
- 'subdir_with space': {
- code: 302,
- location: 'subdir_with%20space/',
- },
- 'subdir_with space/index.html': {
- code: 200,
- type: 'text/html',
- body: 'index :)\n',
- },
- 'containsSymlink/': {
- code: 404,
- body: '<h1>404</h1>\n',
- },
- 'gzip/': {
- code: 200,
- headers: { 'accept-encoding': 'compress, gzip' },
- type: 'text/html',
- body: fs.readFileSync(path.join(__dirname, '../', 'public', 'gzip', 'index.html.gz'), 'utf8'),
- },
- 'gzip/a': {
- code: 404,
- headers: { 'accept-encoding': 'compress, gzip' },
- type: 'text/html',
- body: eol.lf(fs.readFileSync(path.join(__dirname, '../', 'public', '404.html.gz'), 'utf8')),
- },
- 'gzip/real_ecstatic': {
- code: 200,
- file: 'gzip/real_ecstatic',
- headers: { 'accept-encoding': 'compress, gzip' },
- type: 'application/octet-stream',
- body: fs.readFileSync(path.join(__dirname, '../', 'public', 'gzip', 'real_ecstatic.gz'), 'utf8'),
- },
- 'gzip/real_ecstatic.gz': {
- code: 200,
- file: 'gzip/real_ecstatic.gz',
- headers: { 'accept-encoding': 'compress, gzip' },
- type: 'application/gzip',
- body: fs.readFileSync(path.join(__dirname, '../', 'public', 'gzip', 'real_ecstatic.gz'), 'utf8'),
- },
- 'gzip/fake_ecstatic': {
- code: 200,
- file: 'gzip/fake_ecstatic',
- type: 'application/octet-stream',
- headers: { 'accept-encoding': 'compress, gzip' },
- body: 'ecstatic',
- },
- 'gzip/fake_ecstatic.gz': {
- code: 200,
- file: 'gzip/fake_ecstatic.gz',
- type: 'application/gzip',
- headers: { 'accept-encoding': 'compress, gzip' },
- body: fs.readFileSync(path.join(__dirname, '../', 'public', 'gzip', 'fake_ecstatic.gz'), 'utf8'),
- },
- };
- if (require.main === module) {
- /* eslint-disable no-console */
- console.log('ok 1 - test cases included');
- }
|