Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
418523d
Display Jasmine test results in Karma browsers
mattsoulanille Jun 9, 2022
3155ca8
Merge remote-tracking branch 'upstream/master' into karma_jasmine_htm…
mattsoulanille Jun 22, 2022
07bfc7a
[layers] Remove 'async (done) =>' Jasmine antipattern
mattsoulanille Jun 22, 2022
a60eacf
Update jasmine and jasmine types
mattsoulanille Jun 22, 2022
c012e8a
Upgrade karma-jasmine to ~5.1.0 to fix specFilter not working
mattsoulanille Jun 22, 2022
385092e
[webgl] Fix test value type
mattsoulanille Jun 22, 2022
da458a9
[tflite] Fix test esbuild bundle missing input files
mattsoulanille Jun 17, 2022
90422a4
[data] Remove deprecated 'async (done) =>' jasmine style
mattsoulanille Jun 23, 2022
4ebf81b
[data] Use a browser that allows autoplay
mattsoulanille Jun 23, 2022
69b67b0
Comment out 'wasm pre.js' describe, which has only disabled tests
mattsoulanille Jun 23, 2022
6e0cd3d
Remove 'Response' constructor from util_test to work in Node
mattsoulanille Jun 23, 2022
004ef46
Merge remote-tracking branch 'upstream/master' into karma_jasmine_htm…
mattsoulanille Jun 23, 2022
5be5f24
Bump tsconfig lib to es2019
mattsoulanille Jun 23, 2022
75e3cf8
[converter] Avoid spying on properties of the 'tfOps' module
mattsoulanille Jun 23, 2022
4851622
Disable no-any for spyOps type assertion
mattsoulanille Jun 23, 2022
099479e
Add module_name back to converter test lib
mattsoulanille Jun 23, 2022
fa157c2
[converter] Remove deprecated 'async (done) =>' jasmine style
mattsoulanille Jun 24, 2022
e522d10
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 24, 2022
8bdb229
Bazel lint
mattsoulanille Jun 24, 2022
bf939f0
lint
mattsoulanille Jun 24, 2022
e5f586b
Use describeWithFlags instead of an if statement to disable tests tha…
mattsoulanille Jun 24, 2022
bea3ac5
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 27, 2022
d1de3a1
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
1da4de3
Fix lint errors
mattsoulanille Jun 29, 2022
dd2cdce
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
f85c244
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
b2c93fa
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
9a96d24
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
172db2c
Merge branch 'master' into karma_jasmine_html_reporter
mattsoulanille Jun 29, 2022
dc9fc38
Add missing jasmine dependency to automl and update rollup-plugin-typ…
mattsoulanille Jun 29, 2022
241835e
Fix e2e tests
mattsoulanille Jun 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tfjs-node-gpu/node_modules
tfjs-react-native/node_modules
tfjs-tflite/node_modules
tfjs-vis/node_modules
e2e/node_modules
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/argparse": "^1.0.38",
"@types/emscripten": "~0.0.34",
"@types/estree": "^0.0.51",
"@types/jasmine": "~3.0.0",
"@types/jasmine": "~4.0.3",
"@types/js-yaml": "^4.0.5",
"@types/long": "4.0.1",
"@types/mkdirp": "^0.5.2",
Expand All @@ -37,14 +37,15 @@
"core-js": "3",
"deep-equal": "^1.0.1",
"estree-walker": "~1.0.1",
"jasmine": "~3.1.0",
"jasmine-core": "~3.1.0",
"jasmine": "~4.2.1",
"jasmine-core": "~4.2.0",
"js-yaml": "^3.14.0",
"karma": "^6.3.16",
"karma": "^6.4.0",
"karma-browserstack-launcher": "^1.6.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.0",
"karma-jasmine": "~1.0.1",
"karma-chrome-launcher": "^3.1.1",
"karma-firefox-launcher": "^2.1.2",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-requirejs": "^1.1.0",
"karma-sourcemap-loader": "^0.3.8",
"long": "4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions tfjs-backend-wasm/src/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describeWithFlags('wasm init', BROWSER_ENVS, () => {
});
});

describe('wasm pre.js', () => {
// describe('wasm pre.js', () => {
// Temporarily disabled due to node 16 incompatability
// it('works if process variable is undefined', async () => {
// tf.engine().reset();
Expand All @@ -259,4 +259,4 @@ describe('wasm pre.js', () => {
// tf.engine().disposeVariables();
// tf.engine().reset();
// });
});
// });
2 changes: 1 addition & 1 deletion tfjs-backend-webgl/src/backend_webgl_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describeWithFlags('Custom window size', WEBGL_ENVS, () => {
// This will set the screen size to 1x1 to make sure the page limit is
// very small.
spyOnProperty(window, 'screen', 'get')
.and.returnValue({height: 1, width: 1});
.and.returnValue({height: 1, width: 1} as unknown as Screen);

tf.registerBackend(customBackendName, () => new MathBackendWebGL());
tf.setBackend(customBackendName);
Expand Down
34 changes: 22 additions & 12 deletions tfjs-converter/src/operations/executors/control_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ describe('control', () => {
};
const condExecutor = new GraphExecutor(graph);
let firstTime = true;
spyOn(condExecutor, 'executeFunctionAsync').and.callFake(() => {
spyOn(condExecutor, 'executeFunctionAsync').and.callFake(async () => {
if (firstTime) {
firstTime = false;
return input1;
Expand All @@ -447,7 +447,8 @@ describe('control', () => {
});
const bodyExecutor = new GraphExecutor(graph);
const input3 = [tfOps.scalar(3, 'int32')];
spyOn(bodyExecutor, 'executeFunctionAsync').and.returnValue(input3);
spyOn(bodyExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input3));
context.functionMap['bodyFunc'] = bodyExecutor;
context.functionMap['condFunc'] = condExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down Expand Up @@ -488,7 +489,7 @@ describe('control', () => {
};
const condExecutor = new GraphExecutor(graph);
let firstTime = true;
spyOn(condExecutor, 'executeFunctionAsync').and.callFake(() => {
spyOn(condExecutor, 'executeFunctionAsync').and.callFake(async () => {
if (firstTime) {
firstTime = false;
return input1;
Expand All @@ -497,7 +498,8 @@ describe('control', () => {
});
const bodyExecutor = new GraphExecutor(graph);
const input3 = [tfOps.scalar(3, 'int32')];
spyOn(bodyExecutor, 'executeFunctionAsync').and.returnValue(input3);
spyOn(bodyExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input3));
context.functionMap['bodyFunc'] = bodyExecutor;
context.functionMap['condFunc'] = condExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down Expand Up @@ -538,9 +540,11 @@ describe('control', () => {
signature: {}
};
const thenExecutor = new GraphExecutor(graph);
spyOn(thenExecutor, 'executeFunctionAsync').and.returnValue(input1);
spyOn(thenExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input1));
const elseExecutor = new GraphExecutor(graph);
spyOn(elseExecutor, 'executeFunctionAsync').and.returnValue(input2);
spyOn(elseExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input2));
context.functionMap['thenFunc'] = thenExecutor;
context.functionMap['elseFunc'] = elseExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down Expand Up @@ -569,9 +573,11 @@ describe('control', () => {
signature: {}
};
const thenExecutor = new GraphExecutor(graph);
spyOn(thenExecutor, 'executeFunctionAsync').and.returnValue(input1);
spyOn(thenExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input1));
const elseExecutor = new GraphExecutor(graph);
spyOn(elseExecutor, 'executeFunctionAsync').and.returnValue(input2);
spyOn(elseExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input2));
context.functionMap['thenFunc'] = thenExecutor;
context.functionMap['elseFunc'] = elseExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down Expand Up @@ -612,9 +618,11 @@ describe('control', () => {
signature: {}
};
const thenExecutor = new GraphExecutor(graph);
spyOn(thenExecutor, 'executeFunctionAsync').and.returnValue(input1);
spyOn(thenExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input1));
const elseExecutor = new GraphExecutor(graph);
spyOn(elseExecutor, 'executeFunctionAsync').and.returnValue(input2);
spyOn(elseExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input2));
context.functionMap['thenFunc'] = thenExecutor;
context.functionMap['elseFunc'] = elseExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down Expand Up @@ -643,9 +651,11 @@ describe('control', () => {
signature: {}
};
const thenExecutor = new GraphExecutor(graph);
spyOn(thenExecutor, 'executeFunctionAsync').and.returnValue(input1);
spyOn(thenExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input1));
const elseExecutor = new GraphExecutor(graph);
spyOn(elseExecutor, 'executeFunctionAsync').and.returnValue(input2);
spyOn(elseExecutor, 'executeFunctionAsync').and
.returnValue(Promise.resolve(input2));
context.functionMap['thenFunc'] = thenExecutor;
context.functionMap['elseFunc'] = elseExecutor;
const result = await executeOp(node, {cond, input1, input2}, context);
Expand Down
30 changes: 12 additions & 18 deletions tfjs-converter/src/operations/executors/hash_table_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('hash_table', () => {
expect(after).toBe(before + 1);
});

it('should throw if dtype doesnot match.', async (done) => {
it('should throw if dtype doesnot match.', async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand All @@ -135,17 +135,16 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Should fail, succeed unexpectedly.');
fail('Should fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/Expect key dtype/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});

it('should throw if length of keys and values doesnot match.',
async (done) => {
async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand All @@ -161,13 +160,12 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Should fail, succeed unexpectedly.');
fail('Should fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/The number of elements doesn't match/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});

it('should match json def.', () => {
Expand Down Expand Up @@ -200,7 +198,7 @@ describe('hash_table', () => {
expect(after).toBe(before + 1);
});

it('should throw if dtype doesnot match.', async (done) => {
it('should throw if dtype doesnot match.', async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand All @@ -216,17 +214,16 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Should fail, succeed unexpectedly.');
fail('Should fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/Expect key dtype/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});

it('should throw if length of keys and values doesnot match.',
async (done) => {
async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand All @@ -242,13 +239,12 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Should fail, succeed unexpectedly.');
fail('Should fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/The number of elements doesn't match/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});

it('should match json def.', () => {
Expand Down Expand Up @@ -305,7 +301,7 @@ describe('hash_table', () => {
// Create a result tensor.
expect(after).toBe(before + 1);
});
it('should throw if dtype doesnot match.', async (done) => {
it('should throw if dtype doesnot match.', async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand Down Expand Up @@ -341,13 +337,12 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Shoudl fail, succeed unexpectedly.');
fail('Shoudl fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/Expect key dtype/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});
it('should match json def.', () => {
node.op = 'LookupTableFind';
Expand Down Expand Up @@ -403,7 +398,7 @@ describe('hash_table', () => {
// Create a result tensor.
expect(after).toBe(before + 1);
});
it('should throw if dtype doesnot match.', async (done) => {
it('should throw if dtype doesnot match.', async () => {
const hashTable = new HashTable('string', 'float32');

resourceManager.addHashTable('hashtable', hashTable);
Expand Down Expand Up @@ -439,13 +434,12 @@ describe('hash_table', () => {
const before = memory().numTensors;
try {
await executeOp(node, {input3, input5}, context, resourceManager);
done.fail('Shoudl fail, succeed unexpectedly.');
fail('Shoudl fail, succeed unexpectedly.');
} catch (err) {
expect(err).toMatch(/Expect key dtype/);
}
const after = memory().numTensors;
expect(after).toBe(before);
done();
});
it('should match json def.', () => {
node.op = 'LookupTableFindV2';
Expand Down
2 changes: 1 addition & 1 deletion tfjs-converter/src/operations/operation_executor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('OperationExecutor', () => {
const tidySpy = jasmine.createSpy('tidy spy', tfc.tidy);

node.category = category.CATEGORY;
executeOp(node, {}, context, undefined, tidySpy);
executeOp(node, {}, context, undefined, tidySpy as typeof tfc.tidy);
expect(tidySpy).toHaveBeenCalled();
});
});
Expand Down
2 changes: 1 addition & 1 deletion tfjs-core/src/io/browser_files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describeWithFlags('browserDownloads', BROWSER_ENVS, () => {
fakeAnchorCount = 0;
fakeAnchors = [new FakeHTMLAnchorElement(), new FakeHTMLAnchorElement()];
spyOn(document, 'createElement').and.callFake((tag: string) => {
return fakeAnchors[fakeAnchorCount++];
return fakeAnchors[fakeAnchorCount++] as unknown as HTMLElement;
});
});

Expand Down
2 changes: 1 addition & 1 deletion tfjs-core/src/io/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const fakeResponse =
},
headers: {get: (key: string) => contentType},
url: path
});
}) as unknown as Response;

const setupFakeWeightFiles =
(fileBufferMap: {
Expand Down
2 changes: 1 addition & 1 deletion tfjs-core/src/io/weights_loader_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describeWithFlags('loadWeights', BROWSER_ENVS, () => {
[filename: string]: Float32Array|Int32Array|ArrayBuffer|Uint8Array|
Uint16Array
}) => {
spyOn(tf.env().platform, 'fetch').and.callFake((path: string) => {
spyOn(tf.env().platform, 'fetch').and.callFake(async (path: string) => {
return new Response(
fileBufferMap[path],
{headers: {'Content-type': 'application/octet-stream'}});
Expand Down
7 changes: 5 additions & 2 deletions tfjs-core/src/jasmine_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export function setupTestFilters(
const env = jasmine.getEnv();

// Account for --grep flag passed to karma by saving the existing specFilter.
const grepFilter = env.specFilter;
const config = env.configuration();
const grepFilter = config.specFilter;

/**
* Filter method that returns boolean, if a given test should run or be
Expand All @@ -126,7 +127,7 @@ export function setupTestFilters(
* list, it will be exluded.
*/
// tslint:disable-next-line: no-any
env.specFilter = (spec: any) => {
const specFilter = (spec: any) => {
// Filter out tests if the --grep flag is passed.
if (!grepFilter(spec)) {
return false;
Expand Down Expand Up @@ -159,6 +160,8 @@ export function setupTestFilters(
// Otherwise ignore the test.
return false;
};

env.configure({...config, specFilter});
}

export function parseTestEnvFromKarmaFlags(
Expand Down
2 changes: 1 addition & 1 deletion tfjs-core/src/platforms/platform_browser_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {PlatformBrowser} from './platform_browser';
describeWithFlags('PlatformBrowser', BROWSER_ENVS, async () => {
it('fetch calls window.fetch', async () => {
const response = new Response();
spyOn(self, 'fetch').and.returnValue(response);
spyOn(self, 'fetch').and.returnValue(Promise.resolve(response));
const platform = new PlatformBrowser();

await platform.fetch('test/url', {method: 'GET'});
Expand Down
4 changes: 2 additions & 2 deletions tfjs-core/src/platforms/platform_node_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => {
// Null out the system fetch so we force it to require node-fetch.
platform_node.resetSystemFetch();

const testFetch = {fetch: (url: string, init: RequestInit) => {}};
const testFetch = {fetch: (url: string, init: RequestInit) => () => {}};

// Mock the actual fetch call.
spyOn(testFetch, 'fetch').and.returnValue(() => {});
Expand All @@ -71,7 +71,7 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => {
});

it('now should use process.hrtime', async () => {
const time = [100, 200];
const time: [number, number] = [100, 200];
spyOn(process, 'hrtime').and.returnValue(time);
expect(tf.env().platform.now()).toEqual(time[0] * 1000 + time[1] / 1000000);
});
Expand Down
3 changes: 2 additions & 1 deletion tfjs-core/src/util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ describeWithFlags('util.toNestedArray for a complex tensor', ALL_ENVS, () => {

describe('util.fetch', () => {
it('should call the platform fetch', () => {
spyOn(tf.env().platform, 'fetch').and.callFake(() => {});
spyOn(tf.env().platform, 'fetch').and
.callFake(async () => ({} as unknown as Response));

util.fetch('test/path', {method: 'GET'});

Expand Down
1 change: 1 addition & 0 deletions tfjs-data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ tfjs_web_test(
"bs_chrome_mac",
"win_10_chrome",
],
local_browser = "chrome_autoplay",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use chrome_autoplay custom browser so media can play without user interaction.

static_files = [
# Listed here so sourcemaps are served
"//tfjs-data/src:tfjs-data_test_bundle",
Expand Down
Loading