-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cofacts/test
Introduce jest test
- Loading branch information
Showing
19 changed files
with
11,722 additions
and
3,783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**/dist/** | ||
**/node_modules/** | ||
**/node_modules/** | ||
**/rumors-db/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: CI test | ||
|
||
on: | ||
# Triggers the workflow on push or pull request events | ||
- pull_request | ||
- push | ||
# Allows you to run this workflow manually from the Actions tab | ||
- workflow_dispatch | ||
|
||
jobs: | ||
install-and-test: | ||
runs-on: ubuntu-latest | ||
services: | ||
rumors-test-db: | ||
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2 | ||
ports: | ||
- 62223:9200 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm run test -- --coverage | ||
- name: Update coveralls | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "test/rumors-db"] | ||
path = test/rumors-db | ||
url = [email protected]:cofacts/rumors-db.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
hocuspocus-extension-elasticsearch/src/__test__/elasticsearch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
newHocuspocus, | ||
syncedNewHocuspocusProvider, | ||
delayForMs, | ||
} from 'test/utils'; | ||
import { Elasticsearch } from '../elasticsearch'; | ||
import elasticsearch from '@elastic/elasticsearch'; | ||
|
||
describe('elasticsearch extension', () => { | ||
const elasticsearchOpts: elasticsearch.ClientOptions = { | ||
node: process.env.ELASTICSEARCH_URL, | ||
}; | ||
afterEach(async () => { | ||
// server.destroy() does not resolve after cleanup functions such as onStoreDocument called | ||
// thus we should wait for these functions finished | ||
await delayForMs(1000); | ||
}); | ||
|
||
it('return default ydoc when fetched documentName does not exist', async () => { | ||
const server = await newHocuspocus({ | ||
yDocOptions: { gc: false, gcFilter: () => true }, | ||
port: process.env.PORT ? Number(process.env.PORT) : 1234, | ||
extensions: [ | ||
new Elasticsearch({ | ||
elasticsearchOpts, | ||
}), | ||
], | ||
}); | ||
|
||
const provider = await syncedNewHocuspocusProvider(server); | ||
expect(provider.document.share.size).toBe(0); | ||
provider.configuration.websocketProvider.disconnect(); | ||
provider.disconnect(); | ||
|
||
await server.destroy(); | ||
}); | ||
|
||
it('return fetched ydoc', async () => { | ||
const textName = 'test_name'; | ||
const server = await newHocuspocus({ | ||
yDocOptions: { gc: false, gcFilter: () => true }, | ||
port: process.env.PORT ? Number(process.env.PORT) : 1234, | ||
extensions: [ | ||
new Elasticsearch({ | ||
elasticsearchOpts, | ||
}), | ||
], | ||
}); | ||
const provider1 = await syncedNewHocuspocusProvider(server); | ||
const ydoc = provider1.document; | ||
ydoc.getText(textName).insert(0, 'foo'); | ||
provider1.configuration.websocketProvider.disconnect(); | ||
provider1.disconnect(); | ||
|
||
const provider2 = await syncedNewHocuspocusProvider(server); | ||
expect(provider2.document.getText(textName)).toMatchInlineSnapshot(`"foo"`); | ||
provider2.configuration.websocketProvider.disconnect(); | ||
provider2.disconnect(); | ||
|
||
await server.destroy(); | ||
}); | ||
|
||
it('logs error', async () => { | ||
jest.spyOn(global.console, 'error'); | ||
const server = await newHocuspocus({ | ||
yDocOptions: { gc: false, gcFilter: () => true }, | ||
port: 1234, | ||
|
||
extensions: [ | ||
new Elasticsearch({ | ||
elasticsearchOpts: { | ||
node: 'https://wrong-url/', | ||
}, | ||
}), | ||
], | ||
}); | ||
const provider = await syncedNewHocuspocusProvider(server); | ||
expect(console.error).toBeCalledTimes(1); | ||
provider.configuration.websocketProvider.disconnect(); | ||
provider.disconnect(); | ||
|
||
// Note: console.error will be called again because onStoreDocument will be called as server cleanup | ||
await server.destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
// modulePaths: [`<rootDir>/test/utils`], | ||
setupFilesAfterEnv: ['./test/setup.ts'], | ||
coveragePathIgnorePatterns: ['./test/'], | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: './tsconfig.json', | ||
}, | ||
], | ||
}, | ||
}; |
Oops, something went wrong.