Skip to content

Commit

Permalink
Pass mimeTypes option to webpack-dev-middleware (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmohns authored and hiroppy committed Apr 4, 2019
1 parent 05b8fb7 commit abf8691
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/options.json
Expand Up @@ -278,6 +278,9 @@
"noInfo": {
"type": "boolean"
},
"mimeTypes": {
"type": "object"
},
"quiet": {
"type": "boolean"
},
Expand Down Expand Up @@ -342,6 +345,7 @@
"reporter": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserver-reporter)",
"logTime": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-logtime)",
"noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-noinfo-)",
"mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
"quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-quiet-)",
"serverSideRender": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserver-serversiderender)",
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-index)",
Expand Down
26 changes: 26 additions & 0 deletions test/CreateConfig.test.js
Expand Up @@ -516,6 +516,32 @@ describe('createConfig', () => {
expect(config).toMatchSnapshot();
});

it('mimeTypes option', () => {
const config = createConfig(
Object.assign({}, webpackConfig, {
devServer: { mimeTypes: { 'text/html': ['phtml'] } },
}),
argv,
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('mimeTypes option - with force', () => {
const config = createConfig(
Object.assign({}, webpackConfig, {
devServer: {
mimeTypes: { typeMap: { 'text/html': ['phtml'] }, force: true },
},
}),
argv,
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('quiet option', () => {
const config = createConfig(
webpackConfig,
Expand Down
58 changes: 58 additions & 0 deletions test/MimeTypes.test.js
@@ -0,0 +1,58 @@
'use strict';

const request = require('supertest');
const helper = require('./helper');
const config = require('./fixtures/simple-config/webpack.config');

describe('MimeTypes configuration', () => {
afterEach(helper.close);

it('remapping mime type without force should throw an error', () => {
expect(() => {
helper.start(config, {
mimeTypes: { 'application/octet-stream': ['js'] },
});
}).toThrow(/Attempt to change mapping for/);
});

it('remapping mime type with force should not throw an error', (done) => {
helper.start(
config,
{
mimeTypes: {
typeMap: { 'application/octet-stream': ['js'] },
force: true,
},
},
done
);
});
});

describe('custom mimeTypes', () => {
let server;
let req;

beforeAll((done) => {
server = helper.start(
config,
{
mimeTypes: {
typeMap: { 'application/octet-stream': ['js'] },
force: true,
},
},
done
);
req = request(server.app);
});

afterAll(helper.close);

it('request to bundle file with modified mime type', (done) => {
req
.get('/main.js')
.expect('Content-Type', /application\/octet-stream/)
.expect(200, done);
});
});
41 changes: 41 additions & 0 deletions test/__snapshots__/CreateConfig.test.js.snap
Expand Up @@ -671,6 +671,47 @@ Object {
}
`;

exports[`createConfig mimeTypes option - with force 1`] = `
Object {
"hot": true,
"hotOnly": false,
"mimeTypes": Object {
"force": true,
"typeMap": Object {
"text/html": Array [
"phtml",
],
},
},
"noInfo": true,
"port": 8080,
"publicPath": "/",
"stats": Object {
"cached": false,
"cachedAssets": false,
},
}
`;

exports[`createConfig mimeTypes option 1`] = `
Object {
"hot": true,
"hotOnly": false,
"mimeTypes": Object {
"text/html": Array [
"phtml",
],
},
"noInfo": true,
"port": 8080,
"publicPath": "/",
"stats": Object {
"cached": false,
"cachedAssets": false,
},
}
`;

exports[`createConfig open option (boolean) (in devServer config) 1`] = `
Object {
"hot": true,
Expand Down

0 comments on commit abf8691

Please sign in to comment.