Skip to content

Commit d2670ae

Browse files
authored
chore: convert API tests to node test (#1498)
Convert tests that call the Looker API server to use node test runner Test files renamed from `*.spec.ts` to `*.apitest.ts` Only files with `.apitest` use the node test runner
1 parent 748621e commit d2670ae

File tree

13 files changed

+56
-43
lines changed

13 files changed

+56
-43
lines changed

.github/workflows/tssdk-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ jobs:
169169
${{ github.workspace }}/.github/scripts/wait_for_looker.sh
170170
171171
- name: Run Integration Tests
172-
run: yarn test:nodej
172+
run: yarn test:nodeci
173173

174174
- name: Upload integration test results
175175
if: ${{ always() }}

bin/looker-resources-index/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Looker",
1717
"license": "MIT",
1818
"devDependencies": {
19-
"@types/node": "22.5.1",
19+
"@types/node": "22.5.4",
2020
"typescript": "5.5.4"
2121
}
2222
}

jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ module.exports = {
8989
transformIgnorePatterns: [excludeNodeModulesExcept.string],
9090
testPathIgnorePatterns: ['packages/.*?/lib'],
9191
testEnvironment: require.resolve('jest-environment-jsdom'),
92-
// testEnvironment: 'node',
9392
testEnvironmentOptions: {
9493
url: 'http://localhost/',
9594
},

jest.setup.js

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const ResizeObserver = require('resize-observer-polyfill');
3232
require('@testing-library/jest-dom');
3333
require('jest-canvas-mock');
3434
require('jest-styled-components');
35-
// require('jest-environment-node');
3635
require('jest-environment-jsdom');
3736

3837
configure({ adapter: new Adapter() });

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"dev:playground": "yarn workspace @looker/extension-playground develop",
5050
"dev:tile": "yarn workspace @looker/extension-tile-playground develop",
5151
"clean": "rm -Rf packages/*/lib",
52-
"prepublishOnly": "jest packages/sdk-rtl packages/sdk-node/test",
52+
"prepublishOnly": "jest packages/sdk-rtl",
5353
"fix": "yarn lint:es --fix",
5454
"lint": "run-p -c lint:*",
5555
"lint:es": "eslint 'packages/**/*.ts{,x}' --cache",
@@ -70,8 +70,8 @@
7070
"test:gen": "yarn jest packages/sdk-codegen",
7171
"test:redux": "yarn jest packages/redux",
7272
"test:sdk": "yarn jest packages/sdk",
73-
"test:node": "find . -name \"*.test.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test {} ';'",
74-
"test:nodej": "find . -name \"*.test.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test-reporter junit --test {} ';'",
73+
"test:node": "find . -name \"*.apitest.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test {} ';'",
74+
"test:nodeci": "find . -name \"sdk.apitest.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test-reporter junit --test {} ';'",
7575
"test:jest": "DOT_ENV_FILE=.env.test jest",
7676
"test:ext": "yarn jest packages/extension-sdk packages/extension-sdk-react",
7777
"test:hack": "yarn jest packages/wholly-artifact/src packages/hackathon",
@@ -102,7 +102,7 @@
102102
"@types/jest": "29.2.4",
103103
"@types/js-yaml": "^3.12.1",
104104
"@types/lodash": "4.14.172",
105-
"@types/node": "22.5.1",
105+
"@types/node": "22.5.4",
106106
"@types/uuid": "^8.3.4",
107107
"@typescript-eslint/eslint-plugin": "^5.61.0",
108108
"@typescript-eslint/parser": "^5.61.0",

packages/sdk-codegen-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@openapitools/openapi-generator-cli": "^2.1.23",
4040
"@types/config": "^0.0.36",
4141
"dotenv": "^8.2.0",
42+
"expect": "29.7.0",
4243
"file-type": "^16.5.4",
4344
"ini": "^1.3.8",
4445
"js-yaml": "3.14.1",

packages/sdk-codegen-scripts/src/convert.spec.ts packages/sdk-codegen-scripts/src/convert.apitest.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626

2727
import { readFileSync } from 'fs';
28+
import { describe, it } from 'node:test';
29+
import { expect } from 'expect';
2830
import cloneDeep from 'lodash/cloneDeep';
2931
import isEmpty from 'lodash/isEmpty';
3032
import { LookerNodeSDK, NodeSettingsIniFile } from '@looker/sdk-node';
@@ -419,8 +421,7 @@ const settings = new NodeSettingsIniFile(
419421
const sdk = LookerNodeSDK.init40(settings);
420422
const baseUrl = sdk.authSession.settings.base_url;
421423

422-
// TODO get real fetch working for command-line Jest like it does in IntelliJ and VS Code
423-
describe.skip('spec conversion', () => {
424+
describe('spec conversion', () => {
424425
it('swaps out x-looker-tags', () => {
425426
const actual = swapXLookerTags(specFrag);
426427
expect(actual).toContain('"nullable": true');
@@ -584,12 +585,12 @@ describe.skip('spec conversion', () => {
584585
api_server_url: 'http://localhost:19999',
585586
};
586587

587-
test('only gets supported specifications', async () => {
588+
it('only gets supported specifications', async () => {
588589
const actual = await getSpecsFromVersions(versions);
589590
expect(Object.keys(actual)).toEqual(['3.1', '4.0']);
590591
});
591592

592-
test('current is the default spec', async () => {
593+
it('current is the default spec', async () => {
593594
const specs = await getSpecsFromVersions(versions);
594595
const actual = Object.entries(specs).find(
595596
([_, a]) => a.status === 'current'
@@ -603,7 +604,7 @@ describe.skip('spec conversion', () => {
603604
}
604605
});
605606

606-
test('specs have unique keys', async () => {
607+
it('specs have unique keys', async () => {
607608
const moar = cloneDeep(versions);
608609
moar.supported_versions.push(
609610
{

packages/sdk-codegen-scripts/src/fetchSpec.spec.ts packages/sdk-codegen-scripts/src/fetchSpec.apitest.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626

2727
import fs from 'fs';
28+
import { describe, it } from 'node:test';
29+
import { expect } from 'expect';
2830
import { getSpecsFromVersions, specToModel } from '@looker/sdk-codegen';
2931
import { TestConfig } from '@looker/sdk-codegen-utils';
3032
import {
@@ -45,16 +47,15 @@ const props = ApiConfigSection(
4547
// api_version is no longer part of the INI, now set by sdkGen iterator
4648
props.api_version = '4.0';
4749

48-
// TODO get real fetch working for command-line Jest like it does in IntelliJ and VS Code
49-
describe.skip('fetch operations', () => {
50+
describe('fetch operations', () => {
5051
it('defaults lookerVersion when server is not responding', async () => {
5152
const testProps = JSON.parse(JSON.stringify(props));
5253
testProps.base_url = 'https://bogus-server.looker.com:99';
5354
const actual = await fetchLookerVersion(testProps, undefined, {
5455
timeout: 3,
5556
});
5657
expect(actual).toEqual('');
57-
}, 36000);
58+
});
5859

5960
it('gets lookerVersion with good server', async () => {
6061
const actual = await fetchLookerVersion(props);

packages/sdk-node/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
},
3232
"homepage": "https://github.com/looker-open-source/sdk-codegen/tree/main/packages/sdk-node",
3333
"devDependencies": {
34-
"@types/ini": "^1.3.30",
35-
"@types/node": "22.5.1",
34+
"@types/ini": "4.1.1",
35+
"@types/node": "22.5.4",
3636
"dotenv": "^8.2.0",
3737
"expect": "29.7.0",
3838
"whatwg-fetch": "3.6.20",
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"@looker/sdk": "24.16.0",
4343
"@looker/sdk-rtl": "21.6.2",
44-
"ini": "^1.3.8"
44+
"ini": "5.0.0"
4545
},
4646
"keywords": [
4747
"Looker",

packages/sdk-node/src/nodeSession.spec.ts packages/sdk-node/src/nodeSession.apitest.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
*/
2626

2727
import * as fs from 'fs';
28-
// import 'whatwg-fetch';
28+
import * as process from 'node:process';
29+
import { describe, it } from 'node:test';
30+
import { expect } from 'expect';
2931
import { ApiConfigMap, boolDefault, defaultTimeout } from '@looker/sdk-rtl';
30-
import { TestConfig } from '@looker/sdk-codegen-utils';
32+
import { TestConfig } from '@looker/sdk-rtl/src/testUtils';
3133
import { NodeTransport } from './nodeTransport';
3234
import { NodeSession } from './nodeSession';
3335
import { ApiConfig, NodeSettings, NodeSettingsIniFile } from './nodeSettings';
34-
import { specToModel } from '@looker/sdk-codegen';
3536

36-
const config = TestConfig(specToModel);
37+
const config = TestConfig();
3738
const envPrefix = 'LOOKERSDK';
3839
const localIni = config.localIni;
3940

packages/sdk-node/src/nodeTransport.spec.ts packages/sdk-node/src/nodeTransport.apitest.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
2525
*/
2626

27+
import { describe, it } from 'node:test';
28+
import { expect } from 'expect';
2729
import type {
2830
IRawResponse,
2931
ISDKError,
@@ -68,7 +70,7 @@ describe('NodeTransport', () => {
6870
});
6971
});
7072

71-
test('retrieves fully qualified url', async () => {
73+
it('retrieves fully qualified url', async () => {
7274
const response = await xp.request<string, Error>('GET', fullPath);
7375
expect(response).toBeDefined();
7476
expect(response.ok).toEqual(true);
@@ -168,15 +170,15 @@ describe('NodeTransport', () => {
168170
expect((typed as any).num4).toBe(4);
169171
});
170172
describe('NodeCryptoHash', () => {
171-
test('secureRandom', () => {
173+
it('secureRandom', () => {
172174
const hasher = new NodeCryptoHash();
173175
const rand1 = hasher.secureRandom(5);
174176
expect(rand1.length).toEqual(10);
175177
const rand2 = hasher.secureRandom(32);
176178
expect(rand2.length).toEqual(64);
177179
});
178180

179-
test('sha256hash', async () => {
181+
it('sha256hash', async () => {
180182
const hasher = new NodeCryptoHash();
181183
const message = 'The quick brown fox jumped over the lazy dog.';
182184
const hash = await hasher.sha256Hash(message);

packages/sdk-node/test/sdk.test.ts packages/sdk-node/test/sdk.apitest.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
*/
2626

27+
import * as process from 'node:process';
2728
import { before, beforeEach, after, afterEach, describe, it } from 'node:test';
2829
import { createWritableStream, LookerNodeSDK, readIniConfig } from '../src';
2930
import { expect } from 'expect';
@@ -57,10 +58,6 @@ import { TestConfig } from '@looker/sdk-codegen-utils';
5758
import { specToModel } from '@looker/sdk-codegen';
5859
import fs from 'fs';
5960

60-
// TODO Temporary equivalents to ease porting
61-
const beforeAll = before;
62-
const afterAll = after;
63-
6461
/** Note, these tests are for the Node test runner because jest has trouble with
6562
* real calls to node's native fetch functionality
6663
*/
@@ -423,11 +420,11 @@ describe('LookerNodeSDK integration tests', () => {
423420
});
424421

425422
describe('User CRUD-it checks', () => {
426-
beforeAll(async () => {
423+
before(async () => {
427424
await removeTestUsers();
428425
});
429426

430-
afterAll(async () => {
427+
after(async () => {
431428
await removeTestUsers();
432429
});
433430

@@ -477,7 +474,7 @@ describe('LookerNodeSDK integration tests', () => {
477474
});
478475

479476
describe('User searches', () => {
480-
beforeAll(async () => {
477+
before(async () => {
481478
await removeTestUsers();
482479
await createTestUsers();
483480
});
@@ -608,7 +605,8 @@ describe('LookerNodeSDK integration tests', () => {
608605
let count = 0;
609606
let actual: IDashboard[] = [];
610607
const aggregate = (page: IDashboard[]) => {
611-
console.log(`Page ${++count} has ${page.length} items`);
608+
count++;
609+
// console.log(`Page ${count} has ${page.length} items`);
612610
actual = actual.concat(page);
613611
return page;
614612
};
@@ -631,7 +629,8 @@ describe('LookerNodeSDK integration tests', () => {
631629
let count = 0;
632630
let actual: IDashboard[] = [];
633631
const aggregate = (page: IDashboard[]) => {
634-
console.log(`Page ${++count} has ${page.length} items`);
632+
count++;
633+
// console.log(`Page ${count} has ${page.length} items`);
635634
actual = actual.concat(page);
636635
return page;
637636
};
@@ -762,7 +761,7 @@ describe('LookerNodeSDK integration tests', () => {
762761

763762
describe('parses a query with no results', () => {
764763
let query;
765-
beforeAll(async () => {
764+
before(async () => {
766765
query = await sdk.ok(
767766
sdk.create_query({
768767
model: 'system__activity',
@@ -813,7 +812,7 @@ describe('LookerNodeSDK integration tests', () => {
813812
return qhash[Object.keys(qhash)[0]].id;
814813
};
815814

816-
beforeAll(async () => {
815+
before(async () => {
817816
// test dashboards are removed here, but not in top-level tear-down because
818817
// we may want to view them after the test
819818
await removeTestDashboards();
@@ -1013,7 +1012,7 @@ describe('LookerNodeSDK integration tests', () => {
10131012
});
10141013

10151014
describe('Node environment', () => {
1016-
beforeAll(() => {
1015+
before(() => {
10171016
const section = readIniConfig(
10181017
config.localIni,
10191018
environmentPrefix,
@@ -1029,7 +1028,7 @@ describe('LookerNodeSDK integration tests', () => {
10291028
process.env[strLookerVerifySsl] = verify_ssl.toString();
10301029
});
10311030

1032-
afterAll(() => {
1031+
after(() => {
10331032
// reset environment variables
10341033
delete process.env[strLookerTimeout];
10351034
delete process.env[strLookerClientId];

yarn.lock

+14-4
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,11 @@
38603860
dependencies:
38613861
"@types/node" "*"
38623862

3863+
3864+
version "4.1.1"
3865+
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-4.1.1.tgz#6984664a8cc74c3348f4049d0bf2b1ab2d061ca3"
3866+
integrity sha512-MIyNUZipBTbyUNnhvuXJTY7B6qNI78meck9Jbv3wk0OgNwRyOOVEKDutAkOs1snB/tx0FafyR6/SN4Ps0hZPeg==
3867+
38633868
"@types/ini@^1.3.30":
38643869
version "1.3.31"
38653870
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-1.3.31.tgz#c78541a187bd88d5c73e990711c9d85214800d1b"
@@ -3974,10 +3979,10 @@
39743979
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
39753980
integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==
39763981

3977-
"@types/node@*", "@types/[email protected].1", "@types/node@>= 8":
3978-
version "22.5.1"
3979-
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.1.tgz#de01dce265f6b99ed32b295962045d10b5b99560"
3980-
integrity sha512-KkHsxej0j9IW1KKOOAA/XBA0z08UFSrRQHErzEfA3Vgq57eXIMYboIlHJuYIfd+lwCQjtKqUu3UnmKbtUc9yRw==
3982+
"@types/node@*", "@types/[email protected].4", "@types/node@>= 8":
3983+
version "22.5.4"
3984+
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.4.tgz#83f7d1f65bc2ed223bdbf57c7884f1d5a4fa84e8"
3985+
integrity sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==
39813986
dependencies:
39823987
undici-types "~6.19.2"
39833988

@@ -9867,6 +9872,11 @@ [email protected]:
98679872
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
98689873
integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==
98699874

9875+
9876+
version "5.0.0"
9877+
resolved "https://registry.yarnpkg.com/ini/-/ini-5.0.0.tgz#a7a4615339843d9a8ccc2d85c9d81cf93ffbc638"
9878+
integrity sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw==
9879+
98709880
ini@^1.3.2, ini@^1.3.4, ini@^1.3.8:
98719881
version "1.3.8"
98729882
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"

0 commit comments

Comments
 (0)