Skip to content

Commit 54feceb

Browse files
test(yaml): cover existing trailing-hole serialization
1 parent b09daf0 commit 54feceb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎packages/yaml/test/test.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ test('preserves other object and array serialization returned by a transform', a
145145
expect(module.exports.map.get('key')).toEqual({ self: { $circularReference: 1 } });
146146
});
147147

148+
test('preserves existing serialization of arrays with trailing holes', async () => {
149+
const data = {
150+
allHoles: Array(2),
151+
moreHoles: Array(3),
152+
trailingHole: [1].concat(Array(1)),
153+
trailingHoles: [1].concat(Array(2))
154+
};
155+
const bundle = await rollup.rollup({
156+
input: 'fixtures/numeric-keys/main.js',
157+
plugins: [yaml({ transform: () => data })]
158+
});
159+
const { error, module } = await testBundle(null, bundle);
160+
expect(error).toBeUndefined();
161+
162+
// The existing tosource serializer drops one trailing hole.
163+
for (const key of Object.keys(data)) {
164+
const result = module.exports[key];
165+
expect(result.length).toBe(data[key].length - 1);
166+
for (let index = 0; index < result.length; index += 1) {
167+
expect(index in result).toBe(index in data[key]);
168+
}
169+
}
170+
expect(module.exports.trailingHole[0]).toBe(1);
171+
expect(module.exports.trailingHoles[0]).toBe(1);
172+
});
173+
148174
test('resolves extensionless imports in conjunction with nodeResolve plugin', async () => {
149175
const bundle = await rollup.rollup({
150176
input: 'fixtures/extensionless/main.js',

0 commit comments

Comments
 (0)