mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Enabled all labs flags when testing (#13036)
no issue Shows impact of new code behind labs flags through the existing acceptance/regression tests. Allows for existing tests to be updated to match new behaviour rather than requiring separate tests where individual flags are enabled. Should result in minimal test updating once code reaches GA. - adds a forced `'labs:enabled'` fixture op that edits the `labs` setting to enable all flags then restarts the settings service to pick up the new setting - modifies labs service to not remove ALPHA_FEATURE labs settings when running in a testing environment
This commit is contained in:
parent
139cf448d7
commit
f49f7699aa
7 changed files with 42 additions and 5 deletions
|
@ -187,7 +187,8 @@ module.exports = {
|
||||||
'array',
|
'array',
|
||||||
'string',
|
'string',
|
||||||
'number',
|
'number',
|
||||||
'boolean'
|
'boolean',
|
||||||
|
'object'
|
||||||
]]
|
]]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ module.exports.getAll = () => {
|
||||||
const labs = _.cloneDeep(settingsCache.get('labs')) || {};
|
const labs = _.cloneDeep(settingsCache.get('labs')) || {};
|
||||||
|
|
||||||
ALPHA_FEATURES.forEach((alphaKey) => {
|
ALPHA_FEATURES.forEach((alphaKey) => {
|
||||||
if (labs[alphaKey] && !(config.get('enableDeveloperExperiments'))) {
|
if (labs[alphaKey] && !(config.get('enableDeveloperExperiments') || process.env.NODE_ENV.match(/^testing/))) {
|
||||||
delete labs[alphaKey];
|
delete labs[alphaKey];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -677,8 +677,10 @@ describe('Settings API (canary)', function () {
|
||||||
|
|
||||||
jsonResponse.settings.length.should.eql(1);
|
jsonResponse.settings.length.should.eql(1);
|
||||||
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
||||||
|
|
||||||
|
const jsonObjectRegex = /^\{.*\}$/; // '{...}'
|
||||||
jsonResponse.settings[0].key.should.eql('labs');
|
jsonResponse.settings[0].key.should.eql('labs');
|
||||||
jsonResponse.settings[0].value.should.eql(JSON.stringify({}));
|
jsonResponse.settings[0].value.should.match(jsonObjectRegex);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can read deprecated default_locale', function (done) {
|
it('Can read deprecated default_locale', function (done) {
|
||||||
|
|
|
@ -286,8 +286,10 @@ describe('Settings API (v2)', function () {
|
||||||
|
|
||||||
jsonResponse.settings.length.should.eql(1);
|
jsonResponse.settings.length.should.eql(1);
|
||||||
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
||||||
|
|
||||||
|
const jsonObjectRegex = /^\{.*\}$/; // '{...}'
|
||||||
jsonResponse.settings[0].key.should.eql('labs');
|
jsonResponse.settings[0].key.should.eql('labs');
|
||||||
jsonResponse.settings[0].value.should.eql(JSON.stringify({}));
|
jsonResponse.settings[0].value.should.match(jsonObjectRegex);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can read default_locale deprecated in v3', function (done) {
|
it('Can read default_locale deprecated in v3', function (done) {
|
||||||
|
|
|
@ -303,8 +303,10 @@ describe('Settings API (v3)', function () {
|
||||||
|
|
||||||
jsonResponse.settings.length.should.eql(1);
|
jsonResponse.settings.length.should.eql(1);
|
||||||
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
testUtils.API.checkResponseValue(jsonResponse.settings[0], ['id', 'group', 'key', 'value', 'type', 'flags', 'created_at', 'updated_at']);
|
||||||
|
|
||||||
|
const jsonObjectRegex = /^\{.*\}$/; // '{...}'
|
||||||
jsonResponse.settings[0].key.should.eql('labs');
|
jsonResponse.settings[0].key.should.eql('labs');
|
||||||
jsonResponse.settings[0].value.should.eql(JSON.stringify({}));
|
jsonResponse.settings[0].value.should.match(jsonObjectRegex);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can read deprecated default_locale', function (done) {
|
it('Can read deprecated default_locale', function (done) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ describe('Labs Service', function () {
|
||||||
|
|
||||||
it('returns an alpha flag when dev experiments in toggled', function () {
|
it('returns an alpha flag when dev experiments in toggled', function () {
|
||||||
configUtils.set('enableDeveloperExperiments', true);
|
configUtils.set('enableDeveloperExperiments', true);
|
||||||
|
sinon.stub(process.env, 'NODE_ENV').value('production');
|
||||||
sinon.stub(settingsCache, 'get');
|
sinon.stub(settingsCache, 'get');
|
||||||
settingsCache.get.withArgs('labs').returns({
|
settingsCache.get.withArgs('labs').returns({
|
||||||
multipleProducts: true
|
multipleProducts: true
|
||||||
|
@ -35,6 +36,7 @@ describe('Labs Service', function () {
|
||||||
|
|
||||||
it('returns a falsy alpha flag when dev experiments in NOT toggled', function () {
|
it('returns a falsy alpha flag when dev experiments in NOT toggled', function () {
|
||||||
configUtils.set('enableDeveloperExperiments', false);
|
configUtils.set('enableDeveloperExperiments', false);
|
||||||
|
sinon.stub(process.env, 'NODE_ENV').value('production');
|
||||||
sinon.stub(settingsCache, 'get');
|
sinon.stub(settingsCache, 'get');
|
||||||
settingsCache.get.withArgs('labs').returns({
|
settingsCache.get.withArgs('labs').returns({
|
||||||
multipleProducts: true
|
multipleProducts: true
|
||||||
|
|
|
@ -15,6 +15,7 @@ const emailAnalyticsService = require('../../core/server/services/email-analytic
|
||||||
const permissions = require('../../core/server/services/permissions');
|
const permissions = require('../../core/server/services/permissions');
|
||||||
const settingsService = require('../../core/server/services/settings');
|
const settingsService = require('../../core/server/services/settings');
|
||||||
const settingsCache = require('../../core/server/services/settings/cache');
|
const settingsCache = require('../../core/server/services/settings/cache');
|
||||||
|
const labsService = require('../../core/server/services/labs');
|
||||||
|
|
||||||
// Other Test Utilities
|
// Other Test Utilities
|
||||||
const context = require('./fixtures/context');
|
const context = require('./fixtures/context');
|
||||||
|
@ -536,6 +537,28 @@ const fixtures = {
|
||||||
return Promise.map(DataGenerator.forKnex.snippets, function (snippet) {
|
return Promise.map(DataGenerator.forKnex.snippets, function (snippet) {
|
||||||
return models.Snippet.add(snippet, context.internal);
|
return models.Snippet.add(snippet, context.internal);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async enableAllLabsFeatures() {
|
||||||
|
const labsValue = Object.fromEntries(labsService.WRITABLE_KEYS_ALLOWLIST.map(key => [key, true]));
|
||||||
|
const labsSetting = DataGenerator.forKnex.createSetting({
|
||||||
|
key: 'labs',
|
||||||
|
group: 'labs',
|
||||||
|
type: 'object',
|
||||||
|
value: JSON.stringify(labsValue)
|
||||||
|
});
|
||||||
|
|
||||||
|
const existingLabsSetting = await models.Settings.findOne({key: 'labs'});
|
||||||
|
|
||||||
|
if (existingLabsSetting) {
|
||||||
|
delete labsSetting.id;
|
||||||
|
await models.Settings.edit(labsSetting);
|
||||||
|
} else {
|
||||||
|
await models.Settings.add(labsSetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsCache.shutdown();
|
||||||
|
await settingsService.init();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -624,6 +647,9 @@ const toDoList = {
|
||||||
},
|
},
|
||||||
snippets: function insertSnippets() {
|
snippets: function insertSnippets() {
|
||||||
return fixtures.insertSnippets();
|
return fixtures.insertSnippets();
|
||||||
|
},
|
||||||
|
'labs:enabled': function enableAllLabsFeatures() {
|
||||||
|
return fixtures.enableAllLabsFeatures();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -660,6 +686,8 @@ const getFixtureOps = (toDos) => {
|
||||||
delete toDos.init;
|
delete toDos.init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixtureOps.push(toDoList['labs:enabled']);
|
||||||
|
|
||||||
// Go through our list of things to do, and add them to an array
|
// Go through our list of things to do, and add them to an array
|
||||||
_.each(toDos, function (value, toDo) {
|
_.each(toDos, function (value, toDo) {
|
||||||
let tmp;
|
let tmp;
|
||||||
|
|
Loading…
Add table
Reference in a new issue