Skip to content
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

Allow presets to define metadata #76

Merged
merged 2 commits into from
Oct 7, 2019
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
1 change: 1 addition & 0 deletions packages/gasket-metadata-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# `@gasket/metadata-plugin`

- Allow presets to define metadata
- Metadata is assigned to gasket instance, and only by this plugin ([#64])
- Uses [Loader] from gasket instance to get [PluginInfo] and [PresetInfo] data
- `gasket.metadata` structure matches loaded infos with functions redacted
Expand Down
10 changes: 10 additions & 0 deletions packages/gasket-metadata-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ module.exports = {
}
presets.forEach(checkPreset);
});

// Loading preset metadata from module
presets.forEach(preset => {
if (preset.module.metadata) {
Object.keys(preset.module.metadata).reduce((acc, cur) => {
acc[cur] = preset.module.metadata[cur];
return acc;
}, preset);
}
});
},
metadata(gasket, pluginData) {
return {
Expand Down
19 changes: 18 additions & 1 deletion packages/gasket-metadata-plugin/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const mockPluginInfo = {

const mockPresetInfo = {
name: '@gasket/mock-preset',
module: {},
metadataKey: 'oldMetadataValue',
module: {
metadata: {
metadataKey: 'metadataValue'
}
},
plugins: [mockPluginInfo]
};

Expand Down Expand Up @@ -124,6 +129,18 @@ describe('Metadata plugin', function () {
it('augments the metadata with data from the lifecycle hooks', async function () {
assume(gasket.metadata.plugins[0]).property('modified', true);
});
});

describe('presets metadata', function () {
it('loads preset metadata', async function () {
await plugin.hooks.init(gasket);
assume(gasket.metadata.presets[0]).property('metadataKey', 'metadataValue');
});

it('overrides the value if a collision is found', async function () {
assume(mockPresetInfo).property('metadataKey', 'oldMetadataValue');
await plugin.hooks.init(gasket);
assume(gasket.metadata.presets[0]).property('metadataKey', 'metadataValue');
});
});
});