Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e typescript esm conversion #3533

Merged
merged 28 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
20ce17d
first pass on converting to typescript
jsnoble Jan 26, 2024
f88ec28
get it building, set type to module in e2e
jsnoble Jan 30, 2024
d291c3f
revert client changes to do in a future PR
jsnoble Jan 30, 2024
5090862
bump package version of e2e;
jsnoble Jan 30, 2024
2077377
try removing e2e from pathing in top level tsconfig
jsnoble Jan 30, 2024
971fc8f
more cleanup, remove require statements for job imports
jsnoble Jan 31, 2024
4fe1c12
fix jest e2e
jsnoble Jan 31, 2024
a0aeb31
remove __dirname references
jsnoble Jan 31, 2024
5d8c706
fix jest shutdown filepath, and remove double calls for global shutdo…
jsnoble Feb 1, 2024
fc906a1
make sure to compile e2e code
jsnoble Feb 2, 2024
e86ecec
fix pathing typos
jsnoble Feb 6, 2024
7fe5c57
seperate teardown logic and fix pathing for autoload
jsnoble Feb 7, 2024
bee24b3
fix package.json
jsnoble Feb 7, 2024
f582ca0
reintroduce e2e build to top level tsconfig
jsnoble Feb 7, 2024
098639d
bump: (patch) @terascope/types@0.12.2, @terascope/utils@0.53.1
jsnoble Feb 7, 2024
8331584
fix scripts auto inserting of e2e
jsnoble Feb 7, 2024
f6923c2
update packages, comment out module config for testing
jsnoble Feb 7, 2024
fb4bbdf
merge master
jsnoble Feb 7, 2024
d0c236a
update packages, ingore e2e in linting
jsnoble Feb 7, 2024
e426fcf
update yarn
jsnoble Feb 7, 2024
1cbab94
update packages
jsnoble Feb 7, 2024
2a21c98
adjust transforms for testing
jsnoble Feb 7, 2024
389382e
fix yarn.lock
jsnoble Feb 7, 2024
ca516ff
try adding type module to top level package.json
jsnoble Feb 7, 2024
96a2541
revert type module
jsnoble Feb 7, 2024
e682e28
fix transform error for teraslice esm module and config pathing issue
jsnoble Feb 8, 2024
38a4617
re-enable lint for teraslice and e2e
jsnoble Feb 9, 2024
4ac9abd
merge from master and fix defaultNodeVersion for e2e
jsnoble Feb 9, 2024
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
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@terascope",
"rules": {
"@typescript-eslint/naming-convention": "off"
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-duplicate-enum-values": "warn"
},
"ignorePatterns":["packages/teraslice"]
"ignorePatterns":[]
}
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ jobs:
env:
YARN_SETUP_ARGS: "--prod=false --silent"

- name: Compile e2e code
run: yarn build
working-directory: ./e2e

- name: Test ${{ matrix.search-version }}
run: yarn --silent test:${{ matrix.search-version }} --node-version ${{ matrix.node-version }}
working-directory: ./e2e
Expand Down Expand Up @@ -275,6 +279,10 @@ jobs:
env:
YARN_SETUP_ARGS: "--prod=false --silent"

- name: Compile e2e code
run: yarn build
working-directory: ./e2e

- name: Install Kind and Kubectl
uses: helm/kind-action@v1.8.0
with:
Expand Down
12 changes: 12 additions & 0 deletions e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@terascope",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-duplicate-enum-values": "warn"
},
"ignorePatterns":[]
}
67 changes: 39 additions & 28 deletions e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
'use strict';
/* eslint-disable import/no-import-module-exports */
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const config = require('../jest.config.base')(__dirname);
const dirPath = fileURLToPath(new URL('.', import.meta.url));
const configModulePath = path.join(dirPath, '../jest.config.base.js');

const module = await import(configModulePath);

const config = module.default(dirPath);

// TODO: update arrays to run tests specific to platform.
// First array is for tests skipped in kubernetes.
// Second array is for tests skipped in native.
config.testPathIgnorePatterns = process.env.TEST_PLATFORM === 'kubernetes' ? ['data/recovery-spec', 'cluster/worker-allocation-spec', 'cluster/state-spec'] : [];
config.collectCoverage = false;
delete config.transform;
// config.moduleNameMapper = {
// '^(\\.{1,2}/.*)\\.js$': '$1',
// };
config.testTimeout = 3 * 60 * 1000;

config.extensionsToTreatAsEsm = ['.ts'];
config.moduleNameMapper = {
'^(\\.{1,2}/.*)\\.js$': '$1',
};
config.transform = {};
// config.transformIgnorePatterns = [];
// config.transform['^.+\\.(t|j)sx?$'] = ['@swc/jest', {
// jsc: {
// loose: true,
// parser: {
// syntax: 'typescript',
// tsx: false,
// decorators: true
// },
// transform: {
// legacyDecorator: true,
// decoratorMetadata: true
// },
// target: 'es2022'
// },
// module: {
// type: 'commonjs',
// strictMode: false,
// noInterop: false
// }
// }];
config.transform['^.+\\.(t|j)sx?$'] = ['@swc/jest', {
jsc: {
loose: true,
parser: {
syntax: 'typescript',
tsx: false,
decorators: true
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
},
target: 'esnext'
},
module: {
type: 'es6',
strictMode: false,
noInterop: false,
ignoreDynamic: true
}
}];
config.transformIgnorePatterns = [];
config.preset = '';

module.exports = config;
export default config;
14 changes: 9 additions & 5 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "e2e",
"displayName": "E2E Tests",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"description": "Teraslice integration test suite",
"keywords": [
Expand All @@ -19,7 +19,10 @@
},
"license": "MIT",
"author": "Terascope, LLC <info@terascope.io>",
"type": "module",
"scripts": {
"build": "tsc --build",
"build:watch": "yarn build --watch",
"clean": "docker-compose down --volumes --remove-orphans --timeout=5",
"logs": "./scripts/logs.sh",
"logs-follow": "./scripts/logs.sh -f",
Expand All @@ -38,14 +41,15 @@
"ms": "^2.1.3"
},
"devDependencies": {
"@terascope/types": "^0.12.2",
"bunyan": "^1.8.15",
"elasticsearch-store": "^0.76.0",
"fs-extra": "^11.1.1",
"elasticsearch-store": "^0.76.1",
"fs-extra": "^11.2.0",
"ms": "^2.1.3",
"nanoid": "^3.3.4",
"semver": "^7.3.8",
"semver": "^7.6.0",
"signale": "^1.4.0",
"uuid": "^9.0.0"
"uuid": "^9.0.1"
},
"engines": {
"node": ">=14.17.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const fs = require('fs');
const TerasliceHarness = require('../../teraslice-harness');
const { TEST_PLATFORM } = require('../../config');
import 'jest-extended';
import { createReadStream } from 'node:fs';
import { TerasliceHarness, JobFixtureNames } from '../../teraslice-harness.js';
import { TEST_PLATFORM } from '../../config.js';

describe('assets', () => {
let terasliceHarness;
let terasliceHarness: TerasliceHarness;

beforeAll(async () => {
terasliceHarness = new TerasliceHarness();
Expand All @@ -24,8 +23,8 @@ describe('assets', () => {
* @param {string} jobSpecName the name of job to run
* @param {string} assetPath the relative path to the asset file
*/
async function submitAndValidateAssetJob(jobSpecName, assetPath) {
const fileStream = fs.createReadStream(assetPath);
async function submitAndValidateAssetJob(jobSpecName: JobFixtureNames, assetPath: string) {
const fileStream = createReadStream(assetPath);
const jobSpec = terasliceHarness.newJob(jobSpecName);
// Set resource constraints on workers within CI
if (TEST_PLATFORM === 'kubernetes') {
Expand All @@ -43,14 +42,14 @@ describe('assets', () => {

const ex = await terasliceHarness.submitAndStart(jobSpec);

const r = await terasliceHarness.forWorkersJoined(ex.id(), workers, 25);
const r = await terasliceHarness.forWorkersJoined(ex.id(), workers as number, 25);
expect(r).toEqual(workers);

await ex.stop({ blocking: true });
}

it('after uploading an asset, it can be deleted', async () => {
const testStream = fs.createReadStream('test/fixtures/assets/example_asset_1.zip');
const testStream = createReadStream('test/fixtures/assets/example_asset_1.zip');

const result = await terasliceHarness.teraslice.assets.upload(
testStream,
Expand All @@ -72,7 +71,7 @@ describe('assets', () => {
// {"error":"asset.json was not found in root directory of asset bundle
// nor any immediate sub directory"}
it('uploading a bad asset returns an error', async () => {
const testStream = fs.createReadStream('test/fixtures/assets/example_bad_asset_1.zip');
const testStream = createReadStream('test/fixtures/assets/example_bad_asset_1.zip');

try {
await terasliceHarness.teraslice.assets.upload(testStream, { blocking: true });
Expand Down Expand Up @@ -106,7 +105,7 @@ describe('assets', () => {
it('can update an asset bundle and use the new asset', async () => {
const assetPath = 'test/fixtures/assets/example_asset_1updated.zip';

const fileStream = fs.createReadStream(assetPath);
const fileStream = createReadStream(assetPath);
// the asset on this job already points to 'ex1' so it should use the latest available asset
const jobSpec = terasliceHarness.newJob('generator-asset');
// Set resource constraints on workers within CI
Expand All @@ -122,7 +121,11 @@ describe('assets', () => {

const ex = await terasliceHarness.submitAndStart(jobSpec);

const waitResponse = await terasliceHarness.forWorkersJoined(ex.id(), workers, 25);
const waitResponse = await terasliceHarness.forWorkersJoined(
ex.id(),
workers as number,
25
);
expect(waitResponse).toEqual(workers);

const execution = await ex.config();
Expand All @@ -145,7 +148,11 @@ describe('assets', () => {

const ex = await terasliceHarness.submitAndStart(jobSpec);

const waitResponse = await terasliceHarness.forWorkersJoined(ex.id(), workers, 25);
const waitResponse = await terasliceHarness.forWorkersJoined(
ex.id(),
workers as number,
25
);
expect(waitResponse).toEqual(workers);

const execution = await ex.config();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';

const fs = require('fs');
const { cloneDeep, pDelay } = require('@terascope/utils');
const TerasliceHarness = require('../../teraslice-harness');
const { TEST_PLATFORM } = require('../../config');
import { createReadStream } from 'node:fs';
import { cloneDeep, pDelay } from '@terascope/utils';
import { TerasliceHarness } from '../../teraslice-harness.js';
import { TEST_PLATFORM } from '../../config.js';

describe('cluster api', () => {
let terasliceHarness;
let terasliceHarness: TerasliceHarness;

beforeAll(async () => {
terasliceHarness = new TerasliceHarness();
Expand All @@ -16,7 +14,7 @@ describe('cluster api', () => {

it('submitted jobs are not saved in validated form', async () => {
const assetPath = 'test/fixtures/assets/example_asset_1.zip';
const testStream = fs.createReadStream(assetPath);
const testStream = createReadStream(assetPath);
const jobSpec = terasliceHarness.newJob('generator-asset');
// Set resource constraints on workers within CI
if (TEST_PLATFORM === 'kubernetes') {
Expand Down Expand Up @@ -69,10 +67,15 @@ describe('cluster api', () => {
if (TEST_PLATFORM === 'kubernetes') {
jobSpec.resources_requests_cpu = 0.05;
}

if (!jobSpec.operations) {
jobSpec.operations = [];
}

jobSpec.operations[0].index = terasliceHarness.getExampleIndex(100);
jobSpec.operations[1].index = specIndex;

async function didError(p) {
async function didError(p: Promise<void>) {
try {
await p;
return false;
Expand All @@ -91,9 +94,13 @@ describe('cluster api', () => {
await pDelay(100);

const result = await Promise.all([
// @ts-expect-error
didError(terasliceHarness.teraslice.cluster.post(`/jobs/${jobId}/_resume`)),
// @ts-expect-error
didError(terasliceHarness.teraslice.cluster.post(`/jobs/${jobId}/_pause`)),
// @ts-expect-error
didError(terasliceHarness.teraslice.cluster.post(`/ex/${exId}/_resume`)),
// @ts-expect-error
didError(terasliceHarness.teraslice.cluster.post(`/ex/${exId}/_pause`))
]);

Expand Down Expand Up @@ -136,11 +143,13 @@ describe('cluster api', () => {
});

it('api end point /txt/assets/assetName should return a text table', async () => {
// @ts-expect-error
const response = await terasliceHarness.teraslice.cluster.txt('assets/ex1');
expect(response).toBeString();
});

it('api end point /txt/assets/assetName/version should return a text table', async () => {
// @ts-expect-error
const response = await terasliceHarness.teraslice.cluster.txt('assets/ex1/0.0.1');
expect(response).toBeString();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

const TerasliceHarness = require('../../teraslice-harness');
const { TEST_PLATFORM } = require('../../config');
import { TerasliceHarness } from '../../teraslice-harness.js';
import { TEST_PLATFORM } from '../../config.js';

describe('job state', () => {
let terasliceHarness;
let terasliceHarness: TerasliceHarness;

beforeAll(async () => {
terasliceHarness = new TerasliceHarness();
Expand All @@ -22,6 +20,11 @@ describe('job state', () => {
jobSpec2.resources_requests_cpu = 0.05;
jobSpec2.cpu_execution_controller = 0.4;
}

if (!jobSpec2.operations) {
jobSpec2.operations = [];
}

jobSpec2.operations[1].name = 'second_generator';

const [ex1, ex2] = await Promise.all([
Expand Down
Loading
Loading