diff --git a/.github/workflows/tssdk-ci.yml b/.github/workflows/tssdk-ci.yml index c777a16df..3a0746150 100644 --- a/.github/workflows/tssdk-ci.yml +++ b/.github/workflows/tssdk-ci.yml @@ -169,7 +169,7 @@ jobs: ${{ github.workspace }}/.github/scripts/wait_for_looker.sh - name: Run Integration Tests - run: yarn test:nodej + run: yarn test:nodeci - name: Upload integration test results if: ${{ always() }} diff --git a/bin/looker-resources-index/package.json b/bin/looker-resources-index/package.json index 57f9e5631..bf364578c 100644 --- a/bin/looker-resources-index/package.json +++ b/bin/looker-resources-index/package.json @@ -16,7 +16,7 @@ "author": "Looker", "license": "MIT", "devDependencies": { - "@types/node": "22.5.1", + "@types/node": "22.5.4", "typescript": "5.5.4" } } diff --git a/jest.config.js b/jest.config.js index 311f822f6..c20ba651c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -89,7 +89,6 @@ module.exports = { transformIgnorePatterns: [excludeNodeModulesExcept.string], testPathIgnorePatterns: ['packages/.*?/lib'], testEnvironment: require.resolve('jest-environment-jsdom'), - // testEnvironment: 'node', testEnvironmentOptions: { url: 'http://localhost/', }, diff --git a/jest.setup.js b/jest.setup.js index 290a1adf0..a037cf679 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -32,7 +32,6 @@ const ResizeObserver = require('resize-observer-polyfill'); require('@testing-library/jest-dom'); require('jest-canvas-mock'); require('jest-styled-components'); -// require('jest-environment-node'); require('jest-environment-jsdom'); configure({ adapter: new Adapter() }); diff --git a/package.json b/package.json index 71b51e302..4ad4d83fb 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "dev:playground": "yarn workspace @looker/extension-playground develop", "dev:tile": "yarn workspace @looker/extension-tile-playground develop", "clean": "rm -Rf packages/*/lib", - "prepublishOnly": "jest packages/sdk-rtl packages/sdk-node/test", + "prepublishOnly": "jest packages/sdk-rtl", "fix": "yarn lint:es --fix", "lint": "run-p -c lint:*", "lint:es": "eslint 'packages/**/*.ts{,x}' --cache", @@ -70,8 +70,8 @@ "test:gen": "yarn jest packages/sdk-codegen", "test:redux": "yarn jest packages/redux", "test:sdk": "yarn jest packages/sdk", - "test:node": "find . -name \"*.test.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test {} ';'", - "test:nodej": "find . -name \"*.test.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test-reporter junit --test {} ';'", + "test:node": "find . -name \"*.apitest.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test {} ';'", + "test:nodeci": "find . -name \"sdk.apitest.ts\" -not -path \"./node_modules/*\" -exec node --import tsx --test-timeout 90000 --test-reporter junit --test {} ';'", "test:jest": "DOT_ENV_FILE=.env.test jest", "test:ext": "yarn jest packages/extension-sdk packages/extension-sdk-react", "test:hack": "yarn jest packages/wholly-artifact/src packages/hackathon", @@ -102,7 +102,7 @@ "@types/jest": "29.2.4", "@types/js-yaml": "^3.12.1", "@types/lodash": "4.14.172", - "@types/node": "22.5.1", + "@types/node": "22.5.4", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.61.0", diff --git a/packages/sdk-codegen-scripts/package.json b/packages/sdk-codegen-scripts/package.json index 9a834e7bc..f5cb5971d 100644 --- a/packages/sdk-codegen-scripts/package.json +++ b/packages/sdk-codegen-scripts/package.json @@ -39,6 +39,7 @@ "@openapitools/openapi-generator-cli": "^2.1.23", "@types/config": "^0.0.36", "dotenv": "^8.2.0", + "expect": "29.7.0", "file-type": "^16.5.4", "ini": "^1.3.8", "js-yaml": "3.14.1", diff --git a/packages/sdk-codegen-scripts/src/convert.spec.ts b/packages/sdk-codegen-scripts/src/convert.apitest.ts similarity index 98% rename from packages/sdk-codegen-scripts/src/convert.spec.ts rename to packages/sdk-codegen-scripts/src/convert.apitest.ts index f8e4798e1..65f3fbfff 100644 --- a/packages/sdk-codegen-scripts/src/convert.spec.ts +++ b/packages/sdk-codegen-scripts/src/convert.apitest.ts @@ -25,6 +25,8 @@ */ import { readFileSync } from 'fs'; +import { describe, it } from 'node:test'; +import { expect } from 'expect'; import cloneDeep from 'lodash/cloneDeep'; import isEmpty from 'lodash/isEmpty'; import { LookerNodeSDK, NodeSettingsIniFile } from '@looker/sdk-node'; @@ -419,8 +421,7 @@ const settings = new NodeSettingsIniFile( const sdk = LookerNodeSDK.init40(settings); const baseUrl = sdk.authSession.settings.base_url; -// TODO get real fetch working for command-line Jest like it does in IntelliJ and VS Code -describe.skip('spec conversion', () => { +describe('spec conversion', () => { it('swaps out x-looker-tags', () => { const actual = swapXLookerTags(specFrag); expect(actual).toContain('"nullable": true'); @@ -584,12 +585,12 @@ describe.skip('spec conversion', () => { api_server_url: 'http://localhost:19999', }; - test('only gets supported specifications', async () => { + it('only gets supported specifications', async () => { const actual = await getSpecsFromVersions(versions); expect(Object.keys(actual)).toEqual(['3.1', '4.0']); }); - test('current is the default spec', async () => { + it('current is the default spec', async () => { const specs = await getSpecsFromVersions(versions); const actual = Object.entries(specs).find( ([_, a]) => a.status === 'current' @@ -603,7 +604,7 @@ describe.skip('spec conversion', () => { } }); - test('specs have unique keys', async () => { + it('specs have unique keys', async () => { const moar = cloneDeep(versions); moar.supported_versions.push( { diff --git a/packages/sdk-codegen-scripts/src/fetchSpec.spec.ts b/packages/sdk-codegen-scripts/src/fetchSpec.apitest.ts similarity index 96% rename from packages/sdk-codegen-scripts/src/fetchSpec.spec.ts rename to packages/sdk-codegen-scripts/src/fetchSpec.apitest.ts index e950ca4a1..06dee82bb 100644 --- a/packages/sdk-codegen-scripts/src/fetchSpec.spec.ts +++ b/packages/sdk-codegen-scripts/src/fetchSpec.apitest.ts @@ -25,6 +25,8 @@ */ import fs from 'fs'; +import { describe, it } from 'node:test'; +import { expect } from 'expect'; import { getSpecsFromVersions, specToModel } from '@looker/sdk-codegen'; import { TestConfig } from '@looker/sdk-codegen-utils'; import { @@ -45,8 +47,7 @@ const props = ApiConfigSection( // api_version is no longer part of the INI, now set by sdkGen iterator props.api_version = '4.0'; -// TODO get real fetch working for command-line Jest like it does in IntelliJ and VS Code -describe.skip('fetch operations', () => { +describe('fetch operations', () => { it('defaults lookerVersion when server is not responding', async () => { const testProps = JSON.parse(JSON.stringify(props)); testProps.base_url = 'https://bogus-server.looker.com:99'; @@ -54,7 +55,7 @@ describe.skip('fetch operations', () => { timeout: 3, }); expect(actual).toEqual(''); - }, 36000); + }); it('gets lookerVersion with good server', async () => { const actual = await fetchLookerVersion(props); diff --git a/packages/sdk-node/package.json b/packages/sdk-node/package.json index ce495b860..21fdcb2f1 100644 --- a/packages/sdk-node/package.json +++ b/packages/sdk-node/package.json @@ -31,8 +31,8 @@ }, "homepage": "https://github.com/looker-open-source/sdk-codegen/tree/main/packages/sdk-node", "devDependencies": { - "@types/ini": "^1.3.30", - "@types/node": "22.5.1", + "@types/ini": "4.1.1", + "@types/node": "22.5.4", "dotenv": "^8.2.0", "expect": "29.7.0", "whatwg-fetch": "3.6.20", @@ -41,7 +41,7 @@ "dependencies": { "@looker/sdk": "24.16.0", "@looker/sdk-rtl": "21.6.2", - "ini": "^1.3.8" + "ini": "5.0.0" }, "keywords": [ "Looker", diff --git a/packages/sdk-node/src/nodeSession.spec.ts b/packages/sdk-node/src/nodeSession.apitest.ts similarity index 95% rename from packages/sdk-node/src/nodeSession.spec.ts rename to packages/sdk-node/src/nodeSession.apitest.ts index 6013b81a0..15e22f6bb 100644 --- a/packages/sdk-node/src/nodeSession.spec.ts +++ b/packages/sdk-node/src/nodeSession.apitest.ts @@ -25,15 +25,16 @@ */ import * as fs from 'fs'; -// import 'whatwg-fetch'; +import * as process from 'node:process'; +import { describe, it } from 'node:test'; +import { expect } from 'expect'; import { ApiConfigMap, boolDefault, defaultTimeout } from '@looker/sdk-rtl'; -import { TestConfig } from '@looker/sdk-codegen-utils'; +import { TestConfig } from '@looker/sdk-rtl/src/testUtils'; import { NodeTransport } from './nodeTransport'; import { NodeSession } from './nodeSession'; import { ApiConfig, NodeSettings, NodeSettingsIniFile } from './nodeSettings'; -import { specToModel } from '@looker/sdk-codegen'; -const config = TestConfig(specToModel); +const config = TestConfig(); const envPrefix = 'LOOKERSDK'; const localIni = config.localIni; diff --git a/packages/sdk-node/src/nodeTransport.spec.ts b/packages/sdk-node/src/nodeTransport.apitest.ts similarity index 96% rename from packages/sdk-node/src/nodeTransport.spec.ts rename to packages/sdk-node/src/nodeTransport.apitest.ts index 7ebbb7c4a..0043e41f1 100644 --- a/packages/sdk-node/src/nodeTransport.spec.ts +++ b/packages/sdk-node/src/nodeTransport.apitest.ts @@ -24,6 +24,8 @@ */ +import { describe, it } from 'node:test'; +import { expect } from 'expect'; import type { IRawResponse, ISDKError, @@ -68,7 +70,7 @@ describe('NodeTransport', () => { }); }); - test('retrieves fully qualified url', async () => { + it('retrieves fully qualified url', async () => { const response = await xp.request('GET', fullPath); expect(response).toBeDefined(); expect(response.ok).toEqual(true); @@ -168,7 +170,7 @@ describe('NodeTransport', () => { expect((typed as any).num4).toBe(4); }); describe('NodeCryptoHash', () => { - test('secureRandom', () => { + it('secureRandom', () => { const hasher = new NodeCryptoHash(); const rand1 = hasher.secureRandom(5); expect(rand1.length).toEqual(10); @@ -176,7 +178,7 @@ describe('NodeTransport', () => { expect(rand2.length).toEqual(64); }); - test('sha256hash', async () => { + it('sha256hash', async () => { const hasher = new NodeCryptoHash(); const message = 'The quick brown fox jumped over the lazy dog.'; const hash = await hasher.sha256Hash(message); diff --git a/packages/sdk-node/test/sdk.test.ts b/packages/sdk-node/test/sdk.apitest.ts similarity index 98% rename from packages/sdk-node/test/sdk.test.ts rename to packages/sdk-node/test/sdk.apitest.ts index 3d86f5ccc..c05dec1b5 100644 --- a/packages/sdk-node/test/sdk.test.ts +++ b/packages/sdk-node/test/sdk.apitest.ts @@ -24,6 +24,7 @@ */ +import * as process from 'node:process'; import { before, beforeEach, after, afterEach, describe, it } from 'node:test'; import { createWritableStream, LookerNodeSDK, readIniConfig } from '../src'; import { expect } from 'expect'; @@ -57,10 +58,6 @@ import { TestConfig } from '@looker/sdk-codegen-utils'; import { specToModel } from '@looker/sdk-codegen'; import fs from 'fs'; -// TODO Temporary equivalents to ease porting -const beforeAll = before; -const afterAll = after; - /** Note, these tests are for the Node test runner because jest has trouble with * real calls to node's native fetch functionality */ @@ -423,11 +420,11 @@ describe('LookerNodeSDK integration tests', () => { }); describe('User CRUD-it checks', () => { - beforeAll(async () => { + before(async () => { await removeTestUsers(); }); - afterAll(async () => { + after(async () => { await removeTestUsers(); }); @@ -477,7 +474,7 @@ describe('LookerNodeSDK integration tests', () => { }); describe('User searches', () => { - beforeAll(async () => { + before(async () => { await removeTestUsers(); await createTestUsers(); }); @@ -608,7 +605,8 @@ describe('LookerNodeSDK integration tests', () => { let count = 0; let actual: IDashboard[] = []; const aggregate = (page: IDashboard[]) => { - console.log(`Page ${++count} has ${page.length} items`); + count++; + // console.log(`Page ${count} has ${page.length} items`); actual = actual.concat(page); return page; }; @@ -631,7 +629,8 @@ describe('LookerNodeSDK integration tests', () => { let count = 0; let actual: IDashboard[] = []; const aggregate = (page: IDashboard[]) => { - console.log(`Page ${++count} has ${page.length} items`); + count++; + // console.log(`Page ${count} has ${page.length} items`); actual = actual.concat(page); return page; }; @@ -762,7 +761,7 @@ describe('LookerNodeSDK integration tests', () => { describe('parses a query with no results', () => { let query; - beforeAll(async () => { + before(async () => { query = await sdk.ok( sdk.create_query({ model: 'system__activity', @@ -813,7 +812,7 @@ describe('LookerNodeSDK integration tests', () => { return qhash[Object.keys(qhash)[0]].id; }; - beforeAll(async () => { + before(async () => { // test dashboards are removed here, but not in top-level tear-down because // we may want to view them after the test await removeTestDashboards(); @@ -1013,7 +1012,7 @@ describe('LookerNodeSDK integration tests', () => { }); describe('Node environment', () => { - beforeAll(() => { + before(() => { const section = readIniConfig( config.localIni, environmentPrefix, @@ -1029,7 +1028,7 @@ describe('LookerNodeSDK integration tests', () => { process.env[strLookerVerifySsl] = verify_ssl.toString(); }); - afterAll(() => { + after(() => { // reset environment variables delete process.env[strLookerTimeout]; delete process.env[strLookerClientId]; diff --git a/yarn.lock b/yarn.lock index 4f1bd96e1..bd9bfa6cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3860,6 +3860,11 @@ dependencies: "@types/node" "*" +"@types/ini@4.1.1": + version "4.1.1" + resolved "https://registry.yarnpkg.com/@types/ini/-/ini-4.1.1.tgz#6984664a8cc74c3348f4049d0bf2b1ab2d061ca3" + integrity sha512-MIyNUZipBTbyUNnhvuXJTY7B6qNI78meck9Jbv3wk0OgNwRyOOVEKDutAkOs1snB/tx0FafyR6/SN4Ps0hZPeg== + "@types/ini@^1.3.30": version "1.3.31" resolved "https://registry.yarnpkg.com/@types/ini/-/ini-1.3.31.tgz#c78541a187bd88d5c73e990711c9d85214800d1b" @@ -3974,10 +3979,10 @@ resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433" integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g== -"@types/node@*", "@types/node@22.5.1", "@types/node@>= 8": - version "22.5.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.1.tgz#de01dce265f6b99ed32b295962045d10b5b99560" - integrity sha512-KkHsxej0j9IW1KKOOAA/XBA0z08UFSrRQHErzEfA3Vgq57eXIMYboIlHJuYIfd+lwCQjtKqUu3UnmKbtUc9yRw== +"@types/node@*", "@types/node@22.5.4", "@types/node@>= 8": + version "22.5.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.4.tgz#83f7d1f65bc2ed223bdbf57c7884f1d5a4fa84e8" + integrity sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg== dependencies: undici-types "~6.19.2" @@ -9867,6 +9872,11 @@ inherits@2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw== +ini@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/ini/-/ini-5.0.0.tgz#a7a4615339843d9a8ccc2d85c9d81cf93ffbc638" + integrity sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw== + ini@^1.3.2, ini@^1.3.4, ini@^1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"