Skip to content

Commit

Permalink
Fix --enable-index-html=false, add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stooit committed Nov 25, 2024
1 parent bff817f commit 5ce1fd0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ function cliMode() {
describe: command.describe,
builder: command.builder,
handler: async (argv) => {
await showActiveConfig();
try {
await showActiveConfig();
const result = await command.handler(argv);
if (result) {
console.log(result);
Expand Down
13 changes: 8 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ async function fromArgs(args = {}, silent = false) {

// Handle enable-index-html setting
if (args['enable-index-html'] !== undefined) {
const enableIndexHtml = args['enable-index-html'] === true || args['enable-index-html'] === '';

// If setting exists in config, ensure it matches
if (config.enableIndexHtml !== undefined &&
config.enableIndexHtml !== args['enable-index-html']) {
config.enableIndexHtml !== enableIndexHtml) {
const currentSetting = config.enableIndexHtml ? 'enabled' : 'disabled';
const requestedSetting = enableIndexHtml ? 'enable' : 'disable';
throw new Error(
'Project was previously deployed with ' +
(config.enableIndexHtml ? '--enable-index-html' : 'no --enable-index-html') +
'. Cannot change this setting after initial deployment.'
`Cannot ${requestedSetting} index.html URLs - this project was deployed with index.html URLs ${currentSetting}`
);
}

// Store the setting if it's the first time
if (config.enableIndexHtml === undefined) {
config.enableIndexHtml = args['enable-index-html'];
config.enableIndexHtml = enableIndexHtml;
save();
}
}
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,21 @@ describe('Config', () => {
await config.fromArgs({ 'enable-index-html': false }, true);
expect.fail('Should have thrown error');
} catch (err) {
expect(err.message).to.include('Cannot change this setting');
expect(err.message).to.equal('Cannot disable index.html URLs - this project was deployed with index.html URLs enabled');
}
});

it('should handle enableIndexHtml false setting', async () => {
// First deployment sets the setting to false
await config.fromArgs({ 'enable-index-html': false }, true);
expect(config.get('enableIndexHtml')).to.be.false;

// Try to enable it later
try {
await config.fromArgs({ 'enable-index-html': true }, true);
expect.fail('Should have thrown error');
} catch (err) {
expect(err.message).to.equal('Cannot enable index.html URLs - this project was deployed with index.html URLs disabled');
}
});

Expand Down

0 comments on commit 5ce1fd0

Please sign in to comment.