|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2022 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import { |
| 8 | + getModule, |
| 9 | + Version, |
| 10 | +} from '@webcomponents/custom-elements-manifest-tools'; |
| 11 | +import { |
| 12 | + CustomElementDeclaration, |
| 13 | + CustomElementExport, |
| 14 | + Package, |
| 15 | +} from 'custom-elements-manifest'; |
| 16 | +import {suite} from 'uvu'; |
| 17 | +import * as assert from 'uvu/assert'; |
| 18 | + |
| 19 | +import {FirestoreRepository} from '../../../lib/firestore/firestore-repository.js'; |
| 20 | + |
| 21 | +const test = suite('FirestoreRepository tests'); |
| 22 | + |
| 23 | +test('Limits element searches to a namespace', async () => { |
| 24 | + const manifest: Package = { |
| 25 | + schemaVersion: '1.0.0', |
| 26 | + readme: 'README.md', |
| 27 | + modules: [ |
| 28 | + { |
| 29 | + kind: 'javascript-module', |
| 30 | + path: 'foo.js', |
| 31 | + exports: [ |
| 32 | + { |
| 33 | + kind: 'custom-element-definition', |
| 34 | + name: 'x-foo', |
| 35 | + declaration: { |
| 36 | + name: 'FooElement', |
| 37 | + }, |
| 38 | + }, |
| 39 | + ], |
| 40 | + declarations: [ |
| 41 | + { |
| 42 | + kind: 'class', |
| 43 | + customElement: true, |
| 44 | + tagName: 'x-foo', |
| 45 | + name: 'FooElement', |
| 46 | + members: [], |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + ], |
| 51 | + }; |
| 52 | + |
| 53 | + const module = getModule(manifest, 'foo.js')!; |
| 54 | + const customElementExport = module.exports![0] as CustomElementExport; |
| 55 | + const customElementDeclaration = |
| 56 | + module.declarations![0] as CustomElementDeclaration; |
| 57 | + |
| 58 | + const repo1 = new FirestoreRepository('firestore-repository-test-1'); |
| 59 | + const repo2 = new FirestoreRepository('firestore-repository-test-2'); |
| 60 | + |
| 61 | + const writeElement = async (repo: FirestoreRepository) => |
| 62 | + repo.writeCustomElements( |
| 63 | + {name: 'foo', version: '1.0.0', description: 'test package'} as Version, |
| 64 | + [ |
| 65 | + { |
| 66 | + package: manifest, |
| 67 | + module, |
| 68 | + export: customElementExport, |
| 69 | + declaration: customElementDeclaration, |
| 70 | + declarationReference: customElementExport.declaration, |
| 71 | + }, |
| 72 | + ], |
| 73 | + ['latest'], |
| 74 | + 'joe' |
| 75 | + ); |
| 76 | + |
| 77 | + await Promise.all([writeElement(repo1), writeElement(repo2)]); |
| 78 | + const [result1, result2] = await Promise.all([ |
| 79 | + repo1.queryElements({query: 'foo'}), |
| 80 | + repo2.queryElements({query: 'foo'}), |
| 81 | + ]); |
| 82 | + assert.equal(result1.length, 1); |
| 83 | + assert.equal(result2.length, 1); |
| 84 | +}); |
| 85 | + |
| 86 | +test.run(); |
0 commit comments