Skip to content

fix: default value of the static option is static #2897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/utils/normalizeOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const path = require('path');
const isAbsoluteUrl = require('is-absolute-url');
const getCompilerConfigArray = require('./getCompilerConfigArray');

Expand All @@ -14,7 +15,7 @@ function normalizeOptions(compiler, options) {
: {};

const defaultOptionsForStatic = {
directory: process.cwd(),
directory: path.join(process.cwd(), 'static'),
staticOptions: {},
publicPath: ['/'],
serveIndex: { icons: true },
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/contentbase-config/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Heyo.
12 changes: 12 additions & 0 deletions test/server/host-option.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';

const path = require('path');
const request = require('supertest');
const config = require('../fixtures/simple-config/webpack.config');
const testServer = require('../helpers/test-server');
const port = require('../ports-map')['host-option'];

const staticDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config'
);

describe('host option', () => {
let server = null;
let req = null;
Expand All @@ -15,6 +21,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
port,
Expand Down Expand Up @@ -44,6 +51,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
// eslint-disable-next-line no-undefined
Expand Down Expand Up @@ -75,6 +83,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
host: null,
Expand Down Expand Up @@ -105,6 +114,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
host: '127.0.0.1',
Expand Down Expand Up @@ -135,6 +145,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
host: 'localhost',
Expand Down Expand Up @@ -165,6 +176,7 @@ describe('host option', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
host: '0.0.0.0',
Expand Down
11 changes: 11 additions & 0 deletions test/server/port-option.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use strict';

const path = require('path');
const request = require('supertest');
const testServer = require('../helpers/test-server');
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map')['port-option'];

const staticDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config'
);

describe('port', () => {
let server = null;
let req = null;
Expand All @@ -15,6 +21,7 @@ describe('port', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
port,
Expand Down Expand Up @@ -45,6 +52,7 @@ describe('port', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
// eslint-disable-next-line no-undefined
Expand Down Expand Up @@ -76,6 +84,7 @@ describe('port', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
port: null,
Expand Down Expand Up @@ -106,6 +115,7 @@ describe('port', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
port: '33333',
Expand Down Expand Up @@ -135,6 +145,7 @@ describe('port', () => {
config,
{
static: {
directory: staticDirectory,
watch: false,
},
port: '33333',
Expand Down
16 changes: 8 additions & 8 deletions test/server/static-directory-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ const testServer = require('../helpers/test-server');
const config = require('../fixtures/contentbase-config/webpack.config');
const port = require('../ports-map')['static-directory-option'];

const publicDirectory = path.resolve(
const staticDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config/public'
);
const otherPublicDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config/other'
'../fixtures/contentbase-config'
);
const publicDirectory = path.resolve(staticDirectory, 'public');
const otherPublicDirectory = path.resolve(staticDirectory, 'other');

describe('static.directory option', () => {
let server;
Expand Down Expand Up @@ -290,7 +288,9 @@ describe('static.directory option', () => {

describe('default to PWD', () => {
beforeAll((done) => {
jest.spyOn(process, 'cwd').mockImplementation(() => publicDirectory);
jest
.spyOn(process, 'cwd')
.mockImplementation(() => path.resolve(staticDirectory));

server = testServer.start(
config,
Expand All @@ -310,7 +310,7 @@ describe('static.directory option', () => {
});

it('Request to page', (done) => {
req.get('/other.html').expect(200, done);
req.get('/index.html').expect(200, done);
});
});

Expand Down
15 changes: 6 additions & 9 deletions test/server/static-publicPath-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ const testServer = require('../helpers/test-server');
const config = require('../fixtures/contentbase-config/webpack.config');
const port = require('../ports-map')['static-publicPath-option'];

const publicDirectory = path.resolve(
const staticDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config/public'
'../fixtures/contentbase-config'
);
const otherPublicDirectory = path.resolve(
__dirname,
'../fixtures/contentbase-config/other'
);

const publicDirectory = path.resolve(staticDirectory, 'public');
const otherPublicDirectory = path.resolve(staticDirectory, 'other');
const staticPublicPath = '/serve-content-base-at-this-url';
const otherStaticPublicPath = '/serve-other-content-at-this-url';

Expand Down Expand Up @@ -191,7 +188,7 @@ describe('static.publicPath option', () => {

describe('default to PWD', () => {
beforeAll((done) => {
jest.spyOn(process, 'cwd').mockImplementation(() => publicDirectory);
jest.spyOn(process, 'cwd').mockImplementation(() => staticDirectory);

server = testServer.start(
config,
Expand All @@ -213,7 +210,7 @@ describe('static.publicPath option', () => {
});

it('Request to page', (done) => {
req.get(`${staticPublicPath}/other.html`).expect(200, done);
req.get(`${staticPublicPath}/index.html`).expect(200, done);
});
});

Expand Down
3 changes: 2 additions & 1 deletion test/server/utils/normalizeOptions.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
const normalizeOptions = require('../../../lib/utils/normalizeOptions');

Expand Down Expand Up @@ -448,7 +449,7 @@ describe('normalizeOptions', () => {

if (data.options.static) {
data.options.static.forEach((staticOpts) => {
if (staticOpts.directory === process.cwd()) {
if (staticOpts.directory === path.join(process.cwd(), 'static')) {
// give an indication in the snapshot that this is the
// current working directory
staticOpts.directory = 'CWD';
Expand Down