diff --git a/tfjs-converter/cloudbuild.yml b/tfjs-converter/cloudbuild.yml index 8197674c864..21291d8286f 100644 --- a/tfjs-converter/cloudbuild.yml +++ b/tfjs-converter/cloudbuild.yml @@ -6,7 +6,7 @@ steps: id: 'yarn-common' args: ['install'] -# Install converter dependencies +# Install converter dependencies. - name: 'node:10' dir: 'tfjs-converter' entrypoint: 'yarn' @@ -14,15 +14,38 @@ steps: args: ['install'] waitFor: ['yarn-common'] -# Run browser tests. +# Run lint. - name: 'node:10' dir: 'tfjs-converter' entrypoint: 'yarn' - id: 'test-browser' - args: ['test-ci'] + id: 'lint' + args: ['lint'] + waitFor: ['yarn'] + +# Generate json file. +- name: 'node:10' + dir: 'tfjs-converter' + entrypoint: 'yarn' + id: 'gen-json' + args: ['gen-json', '--test'] waitFor: ['yarn'] - env: ['BROWSERSTACK_USERNAME=deeplearnjs1', 'NIGHTLY=$_NIGHTLY'] - secretEnv: ['BROWSERSTACK_KEY'] + +# Build the project. +- name: 'node:10' + dir: 'tfjs-converter' + entrypoint: 'yarn' + id: 'build' + args: ['build'] + waitFor: ['gen-json'] + +# Run javascript tests. +- name: 'node:10' + dir: 'tfjs-converter' + entrypoint: 'yarn' + id: 'test-js' + args: ['test-ci'] + waitFor: ['build'] + env: ['NIGHTLY=$_NIGHTLY'] # Run python tests. - name: 'gcr.io/google-appengine/python' @@ -50,10 +73,6 @@ steps: args: ['test-snippets'] waitFor: ['yarn'] -secrets: -- kmsKeyName: projects/learnjs-174218/locations/global/keyRings/tfjs/cryptoKeys/enc - secretEnv: - BROWSERSTACK_KEY: CiQAkwyoIW0LcnxymzotLwaH4udVTQFBEN4AEA5CA+a3+yflL2ASPQAD8BdZnGARf78MhH5T9rQqyz9HNODwVjVIj64CTkFlUCGrP1B2HX9LXHWHLmtKutEGTeFFX9XhuBzNExA= timeout: 1800s logsBucket: 'gs://tfjs-build-logs' substitutions: diff --git a/tfjs-converter/package.json b/tfjs-converter/package.json index 15f24b24a76..582185c261b 100644 --- a/tfjs-converter/package.json +++ b/tfjs-converter/package.json @@ -58,10 +58,9 @@ "build-npm": "./scripts/build-npm.sh", "link-local": "yalc link", "publish-local": "yarn build-npm && yalc push", - "test": "yarn gen-json --test && karma start", - "test-ci": "yarn gen-json --test && yarn build && yarn lint && yarn run-browserstack", + "test": "yarn gen-json --test && ts-node run_tests.ts", + "test-ci": "ts-node run_tests.ts", "test-snippets": "ts-node ./scripts/test_snippets.ts", - "run-browserstack": "karma start --singleRun --browsers='bs_firefox_mac,bs_chrome_mac' --reporters='dots,karma-typescript,BrowserStack'", "lint": "tslint -p . -t verbose", "make-version": "sh -c ./scripts/make-version", "gen-doc": "ts-node ./scripts/gen_doc.ts", diff --git a/tfjs-converter/run_tests.ts b/tfjs-converter/run_tests.ts new file mode 100644 index 00000000000..2fdce3c4f78 --- /dev/null +++ b/tfjs-converter/run_tests.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2020 Google Inc. All Rights Reserved. + * Licensed 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 CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============================================================================= + */ + +// tslint:disable-next-line:no-imports-from-dist +import * as jasmine_util from '@tensorflow/tfjs-core/dist/jasmine_util'; + +// tslint:disable-next-line:no-require-imports +const jasmineCtor = require('jasmine'); +// tslint:disable-next-line:no-require-imports + +Error.stackTraceLimit = Infinity; + +process.on('unhandledRejection', e => { + throw e; +}); + +jasmine_util.setTestEnvs( + [{name: 'test-converter', backendName: 'cpu', flags: {}}]); + +const unitTests = 'src/**/*_test.ts'; + +const runner = new jasmineCtor(); +runner.loadConfig({spec_files: [unitTests], random: false}); +runner.execute(); diff --git a/tfjs-converter/src/operations/executors/dynamic_executor_test.ts b/tfjs-converter/src/operations/executors/dynamic_executor_test.ts index 1f4ddd056f6..4663423178a 100644 --- a/tfjs-converter/src/operations/executors/dynamic_executor_test.ts +++ b/tfjs-converter/src/operations/executors/dynamic_executor_test.ts @@ -55,7 +55,7 @@ describe('dynamic', () => { const input3 = [tfc.tensor1d([1])]; const input4 = [tfc.tensor1d([1])]; const input5 = [tfc.tensor1d([1])]; - spyOn(tfc.image, 'nonMaxSuppressionAsync').and.callThrough(); + spyOn(tfc.image, 'nonMaxSuppressionAsync'); const result = executeOp(node, {input1, input2, input3, input4, input5}, context); expect(tfc.image.nonMaxSuppressionAsync) @@ -88,7 +88,7 @@ describe('dynamic', () => { const input3 = [tfc.tensor1d([1])]; const input4 = [tfc.tensor1d([1])]; const input5 = [tfc.tensor1d([1])]; - spyOn(tfc.image, 'nonMaxSuppressionAsync').and.callThrough(); + spyOn(tfc.image, 'nonMaxSuppressionAsync'); const result = executeOp(node, {input1, input2, input3, input4, input5}, context); expect(tfc.image.nonMaxSuppressionAsync) @@ -125,7 +125,7 @@ describe('dynamic', () => { const input4 = [tfc.tensor1d([1])]; const input5 = [tfc.tensor1d([1])]; const input6 = [tfc.tensor1d([1])]; - spyOn(tfc.image, 'nonMaxSuppressionWithScoreAsync').and.callThrough(); + spyOn(tfc.image, 'nonMaxSuppressionWithScoreAsync').and.returnValue({}); const result = executeOp( node, {input1, input2, input3, input4, input5, input6}, context); expect(tfc.image.nonMaxSuppressionWithScoreAsync) @@ -153,7 +153,7 @@ describe('dynamic', () => { node.op = 'Where'; node.inputParams = {'condition': createTensorAttr(0)}; const input1 = [tfc.scalar(1)]; - spyOn(tfc, 'whereAsync').and.callThrough(); + spyOn(tfc, 'whereAsync'); const result = executeOp(node, {input1}, context); expect((tfc.whereAsync as jasmine.Spy).calls.mostRecent().args[0].dtype) @@ -180,7 +180,7 @@ describe('dynamic', () => { node.inputParams = {'x': createTensorAttr(0), 'y': createTensorAttr(1)}; const input1 = [tfc.scalar(1)]; const input2 = [tfc.scalar(1)]; - spyOn(tfc, 'setdiff1dAsync').and.callThrough(); + spyOn(tfc, 'setdiff1dAsync'); const result = executeOp(node, {input1, input2}, context); expect(tfc.setdiff1dAsync).toHaveBeenCalledWith(input1[0], input2[0]);