diff --git a/src/Strain.js b/src/Strain.js index 5c155b34..4c8b6556 100644 --- a/src/Strain.js +++ b/src/Strain.js @@ -268,7 +268,7 @@ class Strain { this._ownProperties.forEach((key) => { const idx = node.items.findIndex((i) => i.key === key || (i.key.value && i.key.value === key)); - let value = this[key]; + let value = key === 'version-lock' ? this.versionLock : this[key]; if (value && value.toYAMLNode) { value = value.toYAMLNode(); } diff --git a/test/config.test.js b/test/config.test.js index e2448949..ee853a09 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -313,6 +313,18 @@ describe('Helix Config Serializing', () => { assert.equal(actual, expected); }); + it('can serialize back a modified strain with version-lock and modified package', async () => { + const source = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-lock.yaml'), 'utf-8'); + const cfg = await new HelixConfig() + .withSource(source) + .init(); + + cfg.strains.get('default').package = 'bfbde5fbfbde5fbfbde5f'; + const actual = cfg.toYAML(); + const expected = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-lock-package.yaml'), 'utf-8'); + assert.equal(actual, expected); + }); + it('can serialize back a modified strain with modified package (with refs)', async () => { const source = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-with-refs.yaml'), 'utf-8'); const cfg = await new HelixConfig() diff --git a/test/specs/configs/minimal-lock-package.yaml b/test/specs/configs/minimal-lock-package.yaml new file mode 100644 index 00000000..c1edae61 --- /dev/null +++ b/test/specs/configs/minimal-lock-package.yaml @@ -0,0 +1,31 @@ +# Copyright 2018 Adobe. All rights reserved. +# This file is licensed to you under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under +# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +# OF ANY KIND, either express or implied. See the License for the specific language +# governing permissions and limitations under the License. +version: 1 + +definitions: + constants: + defaultRepo: + &myrepo + owner: adobe + repo: project-helix.io + ref: master + strains: + base: + &basestrain + code: *myrepo + content: *myrepo + static: *myrepo + +strains: + - name: default + <<: *basestrain + version-lock: + word2md: 1.2.3 + package: bfbde5fbfbde5fbfbde5f diff --git a/test/specs/configs/minimal-lock.yaml b/test/specs/configs/minimal-lock.yaml new file mode 100644 index 00000000..fa7d99ae --- /dev/null +++ b/test/specs/configs/minimal-lock.yaml @@ -0,0 +1,30 @@ +# Copyright 2018 Adobe. All rights reserved. +# This file is licensed to you under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under +# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +# OF ANY KIND, either express or implied. See the License for the specific language +# governing permissions and limitations under the License. +version: 1 + +definitions: + constants: + defaultRepo: + &myrepo + owner: adobe + repo: project-helix.io + ref: master + strains: + base: + &basestrain + code: *myrepo + content: *myrepo + static: *myrepo + +strains: + - name: default + <<: *basestrain + version-lock: + word2md: 1.2.3