Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
23 changes: 23 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"ignorePatterns": [
"dist/**",
"coverage/**"
],
"categories": {
"correctness": "error",
"suspicious": "error"
},
"rules": {
"eslint/no-new": "off",
"eslint/no-shadow": "off",
"eslint/no-underscore-dangle": "off",
"eslint/no-useless-constructor": "off",
"unicorn/no-array-sort": "off",
"unicorn/no-useless-spread": "off",
"typescript/consistent-type-definitions": [
"error",
"interface"
]
}
}
11 changes: 8 additions & 3 deletions DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ DATA_API_PASSWORD=cassandra
npm run test
```

To run a subset of tests, pass a name pattern:
```shell
npm test -- -g "pattern"
```

### Lint
Run `npm run lint` to run ESLint.
ESLint will point out any formatting and code quality issues it finds.
ESLint can automatically fix some issues: run `npm run lint -- --fix` to tell ESLint to automatically fix what issues it can.
Run `npm run lint` to run oxlint.
oxlint will point out code quality issues it finds.
oxlint can automatically fix some issues: run `npm run lint -- --fix` to tell oxlint to automatically fix what issues it can.
You should try to run `npm run lint` before committing to minimize risk of regressions.

## Update Stargate and Data API versions
Expand Down
33 changes: 33 additions & 0 deletions bin/run-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { spawnSync } from 'child_process';

const args = process.argv.slice(2);
const nodeOptions: string[] = [];
const testFiles: string[] = [];

for (let i = 0; i < args.length; i++) {
const arg = args[i];

if (arg === '-g' || arg === '--grep') {
nodeOptions.push(`--test-name-pattern=${args[++i]}`);
} else if (arg === '--test-name-pattern' && args[i + 1] != null) {
nodeOptions.push(`${arg}=${args[++i]}`);
} else if (arg.startsWith('-')) {
nodeOptions.push(arg);
} else {
testFiles.push(arg);
}
}

const result = spawnSync(process.execPath, [
'--import=tsx',
'--test',
'--test-concurrency=1',
...nodeOptions,
...testFiles
], { stdio: 'inherit' });

if (result.error) {
throw result.error;
}

process.exitCode = result.status ?? 1;
59 changes: 0 additions & 59 deletions eslint.config.js

This file was deleted.

23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"mocha": {
"timeout": 30000
},
"directories": {
"lib": "src",
"test": "tests",
Expand All @@ -48,13 +45,13 @@
"url": "git+https://github.com/stargate/stargate-mongoose.git"
},
"scripts": {
"lint": "eslint .",
"lint": "oxlint",
"pretest": "touch .env",
"test": "env TEST_DOC_DB=dataapi node --env-file=.env ./node_modules/.bin/ts-mocha --forbid-only -p tsconfig.json tests/**/*.test.ts tests/*.test.ts",
"test-astra": "env TEST_DOC_DB=astra node --env-file=.env ./node_modules/.bin/nyc --check-coverage --reporter=text --reporter=lcov ts-mocha --forbid-only -p tsconfig.json tests/**/*.test.ts tests/*.test.ts",
"test-dataapi": "env TEST_DOC_DB=dataapi node --env-file=.env ./node_modules/.bin/nyc --check-coverage --reporter=text --reporter=lcov ts-mocha --forbid-only -p tsconfig.json tests/**/*.test.ts tests/*.test.ts",
"clean-db": "node --env-file=.env ./node_modules/.bin/ts-node --project tsconfig.json bin/clean-db.ts",
"warm-up-tests": "node --env-file=.env ./node_modules/.bin/ts-node --project tsconfig.json bin/warm-up-tests.ts",
"test": "env TEST_DOC_DB=dataapi tsx --env-file=.env bin/run-tests.ts tests/**/*.test.ts tests/*.test.ts",
"test-astra": "env TEST_DOC_DB=astra tsx --env-file=.env bin/run-tests.ts tests/**/*.test.ts tests/*.test.ts",
"test-dataapi": "env TEST_DOC_DB=dataapi tsx --env-file=.env bin/run-tests.ts tests/**/*.test.ts tests/*.test.ts",
"clean-db": "tsx --env-file=.env bin/clean-db.ts",
"warm-up-tests": "tsx --env-file=.env bin/warm-up-tests.ts",
"preinstall": "npm run update-version-file",
"build": "npm run update-version-file && tsc --project tsconfig.build.json",
"build:test": "tsc",
Expand All @@ -69,18 +66,16 @@
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@types/mocha": "^10.0.10",
"@types/node": "^20.18.1",
"@types/sinon": "^17.0.4",
"eslint": "^9.23.0",
"jsdoc-babel": "^0.5.0",
"jsdoc-to-markdown": "^9.1.1",
"mongoose": "^9.1.0",
"nyc": "^17.1.0",
"sinon": "^16.1.1",
"ts-mocha": "^11.1.0",
"typescript": "~6.0",
"typescript-eslint": "^8.35.0"
"tsx": "^4.19.2",
"typescript": "~7.0",
"oxlint": "^1.76.0"
},
"dependencies": {
"@datastax/astra-db-ts": "^2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/collections/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import assert from 'assert';
import mongoose from 'mongoose';
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import { Product, ProductHydratedDoc, createMongooseCollections } from '../../tests/mongooseFixtures';

describe('Options tests', async () => {
before(async function() {
this.timeout(120_000);
await createMongooseCollections(false);
});

Expand Down
1 change: 1 addition & 0 deletions tests/convertSchemaToColumns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { Mongoose, Schema as MongooseSchema } from 'mongoose';
import assert from 'assert';
import { beforeEach, describe, it } from 'node:test';
import convertSchemaToColumns from '../src/convertSchemaToColumns';
import * as AstraMongooseDriver from '../src/driver';

Expand Down
1 change: 1 addition & 0 deletions tests/createAstraUri.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { describe, it } from 'node:test';
import createAstraUri from '../src/createAstraUri';

describe('Utils test', () => {
Expand Down
20 changes: 5 additions & 15 deletions tests/driver/collections.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import {
testClient,
TEST_COLLECTION_NAME
Expand Down Expand Up @@ -41,7 +42,6 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
let mongooseInstance: AstraMongoose;

before(async function() {
this.timeout(120_000);
({ Product, Cart, mongooseInstance } = await createMongooseCollections(false));
});

Expand Down Expand Up @@ -235,7 +235,6 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
);
});
it('API ops tests db.dropCollection() and Model.createCollection()', async function() {
this.timeout(120_000);

let collections = await Product.db.listCollections().then(collections => collections.map(coll => coll.name));
assert.ok(collections.includes(Product.collection.collectionName));
Expand Down Expand Up @@ -787,9 +786,9 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
const res = await mongooseInstance.connection.collection<ProductRawDoc>('products').findOne({});
assert.equal(res!.name, 'Product 1');
});
it('API ops tests connection.listDatabases()', async function() {
it('API ops tests connection.listDatabases()', async function(t) {
if (testClient!.isAstra) {
return this.skip();
return t.skip();
}
const { databases } = await mongooseInstance!.connection.listDatabases();
assert.ok(Array.isArray(databases));
Expand Down Expand Up @@ -1221,7 +1220,7 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
});
});

describe('vectorize', function () {
describe('vectorize', { skip: !testClient!.isAstra }, function () {
const vectorSchema = new Schema(
{
$vector: { type: [Number], default: () => void 0, dimension: 1024 },
Expand Down Expand Up @@ -1256,10 +1255,6 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
let Vector: Model<InferSchemaType<typeof vectorSchema>>;

before(async function() {
if (!testClient!.isAstra) {
return this.skip();
}

mongooseInstance.deleteModel(/Vector/);
Vector = mongooseInstance.model(
'Vector',
Expand Down Expand Up @@ -1324,7 +1319,7 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
});
});

describe('vectorize with select: true', function () {
describe('vectorize with select: true', { skip: !testClient!.isAstra }, function () {
const vectorSchema = new Schema(
{
$vector: { type: [Number], default: () => void 0, dimension: 1024 },
Expand All @@ -1346,10 +1341,6 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
let Vector: Model<InferSchemaType<typeof vectorSchema>>;

before(async function() {
if (!testClient!.isAstra) {
return this.skip();
}

mongooseInstance.deleteModel(/Vector/);
Vector = mongooseInstance.model(
'Vector',
Expand Down Expand Up @@ -1417,7 +1408,6 @@ describe('COLLECTIONS: mongoose Model API level tests with collections', async (
let LexicalModel: Model<InferSchemaType<typeof lexicalSchema>>;

before(async function () {
this.timeout(120_000);

await mongooseInstance.connection.dropCollection(TEST_COLLECTION_NAME);
LexicalModel = mongooseInstance.model('Lexical', lexicalSchema, TEST_COLLECTION_NAME);
Expand Down
2 changes: 1 addition & 1 deletion tests/driver/collections.driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { after, before, describe, it } from 'node:test';
import mongoose from 'mongoose';
import sinon from 'sinon';
import * as AstraMongooseDriver from '../../src/driver';
Expand All @@ -27,7 +28,6 @@ describe('COLLECTIONS: driver based tests', async () => {
let mongooseInstance: AstraMongoose;

before(async function() {
this.timeout(120_000);
({ Product, Cart, mongooseInstance } = await createMongooseCollections(false));
});

Expand Down
3 changes: 1 addition & 2 deletions tests/driver/tables.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { afterEach, before, describe, it } from 'node:test';
import {
testClient
} from '../fixtures';
Expand Down Expand Up @@ -778,8 +779,6 @@ describe('TABLES: Mongoose Model API level tests', async () => {
let LexicalModel: mongoose.Model<InferSchemaType<typeof lexicalSchema>>;

before(async function () {
this.timeout(120_000);

await mongooseInstance.connection.dropCollection(TEST_TABLE_NAME);
LexicalModel = mongooseInstance.model('Lexical', lexicalSchema, TEST_TABLE_NAME);

Expand Down
1 change: 1 addition & 0 deletions tests/driver/tables.driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { after, before, describe, it } from 'node:test';
import mongoose from 'mongoose';
import * as AstraMongooseDriver from '../../src/driver';
import { testClient, TEST_TABLE_NAME } from '../fixtures';
Expand Down
1 change: 1 addition & 0 deletions tests/driver/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import assert from 'assert';
import { afterEach, before, beforeEach, describe, it } from 'node:test';
import { mongooseInstanceTables as mongooseInstance, createMongooseCollections, testDebug } from '../mongooseFixtures';
import mongoose, { Schema, Types } from 'mongoose';
import { randomUUID } from 'crypto';
Expand Down
7 changes: 2 additions & 5 deletions tests/driver/tables.vector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from 'mongoose';
import { Vectorize } from '../../src/driver/vectorize';
import assert from 'assert';
import { before, beforeEach, describe, it } from 'node:test';
import compareTableDefinitions from '../compareTableDefinitions';
import { testClient } from '../fixtures';
import { createMongooseCollections, mongooseInstanceTables as mongooseInstance, testDebug } from '../mongooseFixtures';
Expand Down Expand Up @@ -237,7 +238,7 @@ describe('TABLES: vector search', function() {
});
});

describe('TABLES: vectorize', function () {
describe('TABLES: vectorize', { skip: !testClient!.isAstra }, function () {
interface IVector {
vector: string | number[] | null;
name?: string | null;
Expand All @@ -259,10 +260,6 @@ describe('TABLES: vectorize', function () {
});

before(async function() {
if (!testClient!.isAstra) {
return this.skip();
}

mongooseInstance.deleteModel(/Vector/);
Vector = mongooseInstance.model(
'Vector',
Expand Down
6 changes: 5 additions & 1 deletion tests/mongooseFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { testClient } from './fixtures';
import { Schema, Mongoose, InferSchemaType, SubdocsToPOJOs } from 'mongoose';
import * as AstraMongooseDriver from '../src/driver';
import assert from 'assert';
import { after } from 'node:test';
import compareTableDefinitions from './compareTableDefinitions';
import { plugins } from '../src/driver';
import tableDefinitionFromSchema from '../src/tableDefinitionFromSchema';
Expand Down Expand Up @@ -175,5 +176,8 @@ export async function createMongooseCollections(isTable: boolean) {
}

after(async function disconnectMongooseFixtures() {
await mongooseInstance.disconnect();
await Promise.all([
mongooseInstance.disconnect(),
mongooseInstanceTables.disconnect()
]);
});
Loading