import * as assert from 'assert' ; import { describe , it } from 'mocha' ; import * as path from 'path' ; import * as protobuf from 'protobufjs' ; import * as googleProtoFiles from '../src' ; describe ( 'load' , ( ) => { const TEST_FILE = path . join ( __dirname , '../../test' , 'fixtures' , 'library.proto' ) ; it ( 'should not be able to load test file using protobufjs directly' , done => { protobuf . load ( TEST_FILE ) . then ( ( ) => { done ( Error ( 'should not get here' ) ) ; } ) . catch ( ( ) => { done ( ) ; } ) ; } ) ; it ( 'should load a test file that relies on common protos' , done => { googleProtoFiles . load ( TEST_FILE ) . then ( root => { assert ( root instanceof protobuf . Root ) ; assert ( root . lookup ( 'google.example.library.v1.LibraryService' ) instanceof protobuf . Service ) ; assert ( root . lookup ( 'test.TestMessage' ) instanceof protobuf . Type ) ; done ( ) ; } ) . catch ( done ) ; } ) ; } ) ; describe ( 'loadSync' , ( ) => { const TEST_FILE = path . join ( __dirname , '../../test/fixtures' , 'library.proto' ) ; it ( 'should not be able to load test file using protobufjs directly' , ( ) => { const root = protobuf . loadSync ( TEST_FILE ) ; assert . strictEqual ( root . lookup ( 'google.api.Http' ) , null ) ; } ) ; it ( 'should load a test file that relies on common protos' , ( ) => { const root = googleProtoFiles . loadSync ( TEST_FILE ) ; assert ( root instanceof protobuf . Root ) ; assert ( root . lookup ( 'google.example.library.v1.LibraryService' ) instanceof protobuf . Service ) ; assert ( root . lookup ( 'test.TestMessage' ) instanceof protobuf . Type ) ; } ) ; } ) ; describe ( 'load real proto file' , ( ) => { it ( 'should load speech.v1' , async ( ) => { const root = await googleProtoFiles . load ( googleProtoFiles . speech . v1 ) ; assert ( root . lookup ( 'google.cloud.speech.v1.RecognizeRequest' ) instanceof protobuf . Type ) ; } ) ; it ( 'should load embeddedAssistant.v1alpha2' , async ( ) => { const root = await googleProtoFiles . load ( googleProtoFiles . embeddedAssistant . v1alpha2 ) ; assert ( root . lookup ( 'google.assistant.embedded.v1alpha2.AssistRequest' ) instanceof protobuf . Type ) ; } ) ; } ) ;