Skip to content

Commit db3b348

Browse files
authored
refactor: remove .js ext from ALL local imports across the codebase (#361)
ideally, imports should reference the source file, not the build file. the triger for this change was a requirement for jest to work directly with typescript files rather than the build output. but not just that, this change should move the project to a more standard direction and also improve code editors to better understand the code structure since now they reference the source files.
1 parent 0ef55b4 commit db3b348

115 files changed

Lines changed: 416 additions & 400 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/nodejs.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ on:
44
push:
55
branches:
66
- develop
7+
- test
78
pull_request:
89

910
jobs:
1011
build:
1112
runs-on: 'ubuntu-latest'
1213

14+
1315
steps:
16+
- name: 'Checkout Project'
17+
uses: 'actions/checkout@v4'
18+
1419
- name: Setup Node.js environment
1520
uses: actions/setup-node@v3
1621
with:
1722
node-version: '16.15'
23+
cache: 'yarn'
1824

19-
- name: 'Checkout Project'
20-
uses: 'actions/checkout@v3'
21-
with:
22-
fetch-depth: 1
25+
- name: Install dependencies
26+
run: yarn install --immutable
2327

24-
- name: Install Dependencies and lint code
25-
run: yarn install && yarn lint
28+
- name: Lint code
29+
run: yarn lint
2630

2731
- name: Start MongoDB
2832
uses: supercharge/mongodb-github-action@1.8.0
@@ -44,8 +48,8 @@ jobs:
4448
run: |
4549
docker container restart mongodb
4650
47-
- name: Build and run tests
48-
run: yarn test
49-
env:
50-
NODE_OPTIONS: --experimental-vm-modules
51+
- name: Run tests
52+
run: yarn test --ci
5153

54+
- name: Build files/check types
55+
run: yarn build-release --noEmit

jest.config.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module.exports = {
2-
preset: 'ts-jest',
2+
transform: {
3+
'^.+\\.tsx?$': 'ts-jest'
4+
},
5+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
36
testEnvironment: 'node',
7+
testPathIgnorePatterns: ['/node_modules/', './build/'],
48
testMatch: [
5-
'<rootDir>/build/**/__tests__/*.js'
9+
'<rootDir>/**/__tests__/*.ts'
610
]
711
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"scripts": {
6767
"lint": "yarn ts-standard",
6868
"fix": "yarn ts-standard --fix",
69-
"test": "yarn build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
69+
"test": "jest --runInBand",
7070
"build": "tsc -p tsconfig.json",
7171
"build-release": "tsc -p tsconfig.release.json",
7272
"clean": "tsc -b --clean && rm -rf build/*",

src/GradeUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getScale, GradeScales, GradeScalesTypes } from '@openbeta/sandbag'
22
import isoCountries from 'i18n-iso-countries'
3-
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes.js'
3+
import { DisciplineType, ClimbGradeContextType } from './db/ClimbTypes'
44

55
/**
66
* Grade systems have minor variations between countries. gradeContext is a

src/__tests__/areas.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ApolloServer } from 'apollo-server'
22
import muuid from 'uuid-mongodb'
33
import { jest } from '@jest/globals'
4-
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
5-
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
6-
import { AreaType } from '../db/AreaTypes.js'
7-
import { OrgType, OrganizationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
8-
import { queryAPI, setUpServer } from '../utils/testUtils.js'
9-
import { muuidToString } from '../utils/helpers.js'
4+
import MutableAreaDataSource from '../model/MutableAreaDataSource'
5+
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
6+
import { AreaType } from '../db/AreaTypes'
7+
import { OrgType, OrganizationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes'
8+
import { queryAPI, setUpServer } from '../utils/testUtils'
9+
import { muuidToString } from '../utils/helpers'
1010

1111
jest.setTimeout(60000)
1212

src/__tests__/gradeUtils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { DisciplineType } from '../db/ClimbTypes.js'
2-
import { sanitizeDisciplines, createGradeObject, gradeContextToGradeScales } from '../GradeUtils.js'
1+
import { DisciplineType } from '../db/ClimbTypes'
2+
import { sanitizeDisciplines, createGradeObject, gradeContextToGradeScales } from '../GradeUtils'
3+
4+
beforeAll(() => {
5+
console.warn = jest.fn()
6+
})
7+
8+
afterAll(() => {
9+
jest.mocked(console.warn).mockReset()
10+
})
311

412
describe('Test grade utilities', () => {
513
it('sanitizes bad discipline object', () => {

src/__tests__/history.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ApolloServer } from 'apollo-server'
22
import muuid from 'uuid-mongodb'
33
import { jest } from '@jest/globals'
4-
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
5-
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
6-
import MutableClimbDataSource from '../model/MutableClimbDataSource.js'
7-
import { AreaType } from '../db/AreaTypes.js'
8-
import { OrgType, OrganizationType } from '../db/OrganizationTypes.js'
9-
import { muuidToString } from '../utils/helpers.js'
10-
import { queryAPI, setUpServer } from '../utils/testUtils.js'
4+
import MutableAreaDataSource from '../model/MutableAreaDataSource'
5+
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
6+
import MutableClimbDataSource from '../model/MutableClimbDataSource'
7+
import { AreaType } from '../db/AreaTypes'
8+
import { OrgType, OrganizationType } from '../db/OrganizationTypes'
9+
import { muuidToString } from '../utils/helpers'
10+
import { queryAPI, setUpServer } from '../utils/testUtils'
1111

1212
jest.setTimeout(60000)
1313

src/__tests__/organizations.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ApolloServer } from 'apollo-server'
22
import muuid from 'uuid-mongodb'
33
import { jest } from '@jest/globals'
4-
import MutableAreaDataSource from '../model/MutableAreaDataSource.js'
5-
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource.js'
6-
import { AreaType } from '../db/AreaTypes.js'
7-
import { OrgType, OrganizationType, OperationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes.js'
8-
import { changelogDataSource } from '../model/ChangeLogDataSource.js'
9-
import { queryAPI, setUpServer } from '../utils/testUtils.js'
10-
import { muuidToString } from '../utils/helpers.js'
4+
import MutableAreaDataSource from '../model/MutableAreaDataSource'
5+
import MutableOrganizationDataSource from '../model/MutableOrganizationDataSource'
6+
import { AreaType } from '../db/AreaTypes'
7+
import { OrgType, OrganizationType, OperationType, OrganizationEditableFieldsType } from '../db/OrganizationTypes'
8+
import { changelogDataSource } from '../model/ChangeLogDataSource'
9+
import { queryAPI, setUpServer } from '../utils/testUtils'
10+
import { muuidToString } from '../utils/helpers'
1111
import { validate as validateMuuid } from 'uuid'
1212

1313
jest.setTimeout(60000)

src/__tests__/ticks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ApolloServer } from 'apollo-server'
22
import muuid from 'uuid-mongodb'
33
import { jest } from '@jest/globals'
4-
import { queryAPI, setUpServer } from '../utils/testUtils.js'
5-
import { muuidToString } from '../utils/helpers.js'
6-
import { TickInput } from '../db/TickTypes.js'
7-
import TickDataSource from '../model/TickDataSource.js'
8-
import UserDataSource from '../model/UserDataSource.js'
9-
import { UpdateProfileGQLInput } from '../db/UserTypes.js'
4+
import { queryAPI, setUpServer } from '../utils/testUtils'
5+
import { muuidToString } from '../utils/helpers'
6+
import { TickInput } from '../db/TickTypes'
7+
import TickDataSource from '../model/TickDataSource'
8+
import UserDataSource from '../model/UserDataSource'
9+
import { UpdateProfileGQLInput } from '../db/UserTypes'
1010

1111
jest.setTimeout(60000)
1212

src/auth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import permissions from './permissions.js'
2-
import { createContext } from './middleware.js'
1+
import permissions from './permissions'
2+
import { createContext } from './middleware'
33
export { permissions, createContext }

0 commit comments

Comments
 (0)