xref: /aosp_15_r20/external/pigweed/ts/index_test.ts (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1/**
2 * @jest-environment jsdom
3 */
4
5// Copyright 2022 The Pigweed Authors
6//
7// Licensed under the Apache License, Version 2.0 (the "License"); you may not
8// use this file except in compliance with the License. You may obtain a copy of
9// the License at
10//
11//     https://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16// License for the specific language governing permissions and limitations under
17// the License.
18
19import {
20  pw_status,
21  pw_hdlc,
22  pw_rpc,
23  pw_tokenizer,
24  pw_transfer,
25  WebSerial,
26} from '../dist/index.umd';
27
28import { ProtoCollection } from '../dist/protos/collection.umd';
29import {
30  createLogViewer,
31  MockLogSource,
32  PigweedRPCLogSource,
33} from '../dist/logging.umd';
34import * as fs from 'fs';
35
36describe('Pigweed Bundle', () => {
37  it('proto collection has file list', () => {
38    const protoCollection = new ProtoCollection();
39    const fd = protoCollection.fileDescriptorSet.getFileList();
40    expect(fd.length).toBeGreaterThan(0);
41  });
42
43  it('has pw_status enum defined', () => {
44    const Status = pw_status.Status;
45    expect(Status[Status.OUT_OF_RANGE]).toBeDefined();
46  });
47
48  it('has pw_hdlc frame, frame status, decoder and encoder defined', () => {
49    expect(pw_hdlc.Frame).toBeDefined();
50    expect(pw_hdlc.FrameStatus).toBeDefined();
51    expect(pw_hdlc.Decoder).toBeDefined();
52    expect(pw_hdlc.Encoder).toBeDefined();
53  });
54
55  it('has pw_rpc defined', () => {
56    expect(pw_rpc.Client).toBeDefined();
57    expect(pw_rpc.Rpc).toBeDefined();
58    expect(pw_rpc.Channel).toBeDefined();
59  });
60
61  it('has pw_tokenizer defined', () => {
62    expect(pw_tokenizer.Detokenizer).toBeDefined();
63    expect(pw_tokenizer.PrintfDecoder).toBeDefined();
64  });
65
66  it('has pw_transfer defined', () => {
67    expect(pw_transfer.Manager).toBeDefined();
68  });
69
70  it('has WebSerialTransport defined', () => {
71    expect(WebSerial.WebSerialTransport).toBeDefined();
72  });
73
74  it('has ProgressStats defined', () => {
75    expect(pw_transfer.ProgressStats).toBeDefined();
76  });
77
78  it('has log viewer exports defined', () => {
79    expect(createLogViewer).toBeDefined();
80    expect(typeof createLogViewer).toBe('function');
81
82    expect(MockLogSource).toBeDefined();
83    expect(typeof MockLogSource).toBe('function');
84    expect(MockLogSource.name).toBe('MockLogSource');
85
86    expect(PigweedRPCLogSource).toBeDefined();
87    expect(typeof PigweedRPCLogSource).toBe('function');
88    expect(PigweedRPCLogSource.name).toBe('PigweedRPCLogSource');
89  });
90
91  it('is not referring to any outside Pigweed modules', () => {
92    const requireString = "require('pigweedjs";
93    const file = fs.readFileSync(require.resolve('../dist/index.umd'));
94    expect(file.indexOf(requireString)).toBe(-1);
95  });
96});
97