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 95d780b6d..8171c9e44 100644 --- a/package.json +++ b/package.json @@ -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:nodej": "find . -name \"*.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", diff --git a/packages/sdk-codegen-scripts/package.json b/packages/sdk-codegen-scripts/package.json index 525005b20..7bc99426d 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 ab9a76967..44e2975aa 100644 --- a/packages/sdk-node/package.json +++ b/packages/sdk-node/package.json @@ -33,6 +33,7 @@ "devDependencies": { "@types/ini": "^1.3.30", "@types/node": "22.5.1", + "@looker/sdk-codegen": "21.9.0", "dotenv": "^8.2.0", "expect": "29.7.0", "whatwg-fetch": "3.6.20", diff --git a/packages/sdk-node/src/nodeSession.spec.ts b/packages/sdk-node/src/nodeSession.apitest.ts similarity index 97% rename from packages/sdk-node/src/nodeSession.spec.ts rename to packages/sdk-node/src/nodeSession.apitest.ts index 6013b81a0..5b7db24ba 100644 --- a/packages/sdk-node/src/nodeSession.spec.ts +++ b/packages/sdk-node/src/nodeSession.apitest.ts @@ -25,13 +25,15 @@ */ 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 { specToModel } from '@looker/sdk-codegen'; import { ApiConfigMap, boolDefault, defaultTimeout } from '@looker/sdk-rtl'; import { TestConfig } from '@looker/sdk-codegen-utils'; 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 envPrefix = 'LOOKERSDK'; 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];