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

feat: dual module export #607

Merged
merged 10 commits into from
Oct 18, 2023
Prev Previous commit
Next Next commit
feat: update tests to use .js imports, and update jest config for esm
  • Loading branch information
antstanley committed Oct 18, 2023
commit a9500162816e9900abd8842b8e0a0e54c258ec7c
13 changes: 11 additions & 2 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ module.exports = {
testMatch: ['**/?(*.)+(unit.test).+(ts|tsx|js)'],
testPathIgnorePatterns: ['/__tests__/entities/*', '/__tests__/tables/*'],
coveragePathIgnorePatterns: ['/__tests__/*'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest'
}
'^.+\\.[tj]sx?$': [
'ts-jest',
{
useESM: true,
},
],
},
}
6 changes: 3 additions & 3 deletions src/__tests__/checkAttribute.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import checkAttribute from '../lib/checkAttribute'
import checkAttribute from '../lib/checkAttribute.js'

// Require Table and Entity classes
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

// Create basic table
const DefaultTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity-creation.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test.js'

const tableAddEntity = jest.spyOn(Table.prototype, 'addEntity').mockReturnValue()

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity-properties.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

describe('Entity properties', () => {
describe('table', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/entity.delete.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '..'
import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.get.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.get.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '..'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity.parse.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DocumentClientWithWrappedNumbers } from './bootstrap.test'
import { DocumentClientWithWrappedNumbers } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { unmarshall } from '@aws-sdk/util-dynamodb'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.put.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.putBatch.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.transaction.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity.update.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ATTRIBUTE_VALUES_LIST_DEFAULT_KEY,
ATTRIBUTE_VALUES_LIST_DEFAULT_VALUE
} from '../constants'
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
} from '../constants.js'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/entity.utils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { shouldExecute, shouldParse } from '../classes/Entity'
import { shouldExecute, shouldParse } from '../classes/Entity/Entity.js'

describe('Entity - utils', () => {
it('should execute', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/expressionBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import {
default as expressionBuilder,
SUPPORTED_FILTER_EXP_ATTR_REF_OPERATORS
} from '../lib/expressionBuilder'
} from '../lib/expressionBuilder.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/format.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/formatItem.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import formatItem from '../lib/formatItem'
import formatItem from '../lib/formatItem.js'

import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

// Create basic table
const DefaultTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/misc-tests.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

describe('Misc Tests (development only)', () => {
it('uses a numeric pk value', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/normalizeData.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import normalizeData from '../lib/normalizeData'
import normalizeData from '../lib/normalizeData.js'

import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

const DefaultTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/parse-alias.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-alias',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/parse.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseCompositeKey.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackingInfo } from '../lib/parseEntity'
import parseCompositeKey from '../lib/parseCompositeKey'
import { TrackingInfo } from '../lib/parseEntity.js'
import parseCompositeKey from '../lib/parseCompositeKey.js'

// Simulate attributes
const attributes = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/parseEntity.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parseEntity from '../lib/parseEntity'
import parseEntity from '../lib/parseEntity.js'

// Simulate Entity config
const entity = {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseMapping.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parseMapping from '../lib/parseMapping'
import { TrackingInfo } from '../lib/parseEntity'
import parseMapping from '../lib/parseMapping.js'
import { TrackingInfo } from '../lib/parseEntity.js'

let track: TrackingInfo = {
fields: [],
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseTable.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import parseTable from '../lib/parseTable'
import parseTable from '../lib/parseTable.js'

// Require Table and Entity classes
import { TableConstructor } from '../classes/Table'
import { TableConstructor } from '../classes/Table/types.js'

const table: TableConstructor<'test-table', 'pk', 'sk'> = {
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseTableAttributes.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TableAttributes } from '../classes/Table'
import parseTableAttributes from '../lib/parseTableAttributes'
import { TableAttributes } from '../classes/Table/types.js'
import parseTableAttributes from '../lib/parseTableAttributes.js'

const attrs: TableAttributes = {
pk: 'string',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/projectionBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import projectionBuilder from '../lib/projectionBuilder'
import projectionBuilder from '../lib/projectionBuilder.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

const DefaultTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table-creation.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Table from '../classes/Table'
import { DocumentClient, DocumentClientWithoutConfig } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import { DocumentClient, DocumentClientWithoutConfig } from './bootstrap.test.js'

describe('Table creation', () => {
it('creates table w/ minimum options', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.batchGet.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.batchWrite.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BatchWriteCommandInput } from '@aws-sdk/lib-dynamodb'
import { Entity, Table } from '../index'
import { DocumentClient as docClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient as docClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.entities.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

let TestTable: any
let TestEntity: any
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.entity-actions.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.query.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.scan.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.transactGet.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.transactWrite.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient as docClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient as docClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/type-infering.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
PutCommandInput, PutCommandOutput, QueryCommandInput, ScanCommandInput,
UpdateCommandInput, UpdateCommandOutput,
} from '@aws-sdk/lib-dynamodb'
import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

const omit = <O extends Record<string, unknown>, K extends (keyof O)[]>(
obj: O,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/utils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toBool, hasValue, error } from '../lib/utils'
import { toBool, hasValue, error } from '../lib/utils.js'

describe('utility functions', () => {
test('toBool', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/validateTypes.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toDynamoBigInt } from '../lib/utils'
import validateTypes from '../lib/validateTypes'
import { toDynamoBigInt } from '../lib/utils.js'
import validateTypes from '../lib/validateTypes.js'

describe('validateTypes', () => {
it('validates string', async () => {
Expand Down
Loading