Skip to content

Commit 9de2b99

Browse files
authored
Cleanup for private preview (#11)
* Add a quick manual integration test * Tweak to readme example * Update publish rules * Add coverage reporting options * A few more artifacts borrowed from elasticsearch-js * Fix dockerignore
1 parent b3d47f9 commit 9de2b99

File tree

6 files changed

+125
-5
lines changed

6 files changed

+125
-5
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
.git
4+
.nyc_output
5+
lib

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
303 See Other
2+
3+
Location: https://www.elastic.co/community/codeofconduct

NOTICE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Elasticsearch JavaScript Client
2+
Copyright 2022 Elasticsearch B.V.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ npm install @elastic/elasticsearch-serverless
2727
```javascript
2828
const { Client } = require('@elastic/elasticsearch-serverless')
2929
const client = new Client({
30-
cloud: { id: '<cloud-id>' },
31-
auth: { apiKey: 'base64EncodedKey' }
30+
node: 'https://', // serverless project URL
31+
auth: { apiKey: 'your_api_key' }, // project API key
3232
})
33-
3433
```
3534

3635
### Using the API

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "elasticsearch-serverless",
3-
"private": true,
43
"version": "0.1.0+20231031",
54
"description": "The official Node.js Elastic client for the Elasticsearch Serverless service.",
65
"main": "index.js",
@@ -12,7 +11,11 @@
1211
"prebuild": "npm run clean-build && npm run lint",
1312
"build": "tsc",
1413
"clean-build": "rimraf ./lib && mkdir lib",
15-
"test": "npm run build && npm run lint && tap test/unit/{*,**/*}.test.ts",
14+
"prepublishOnly": "npm run build",
15+
"test": "npm run build && npm run lint && tap test/unit/{*,**/*}.test.ts && npm run license-checker",
16+
"test:coverage-100": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage --100",
17+
"test:coverage-report": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage && nyc report --reporter=text-lcov > coverage.lcov",
18+
"test:coverage-ui": "npm run build && tap test/unit/{*,**/*}.test.ts --coverage --coverage-report=html",
1619
"test:unit": "npm run build && tap test/unit/{*,**/*}.test.ts"
1720
},
1821
"keywords": [

test/integration/manual.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
process.on('unhandledRejection', function (err) {
21+
console.error(err)
22+
process.exit(1)
23+
})
24+
25+
import { Client } from '../../'
26+
import assert from 'node:assert'
27+
28+
async function main () {
29+
// a simple manual smoke test that can be run against a fresh serverless instance
30+
const { ELASTICSEARCH_URL, ES_API_SECRET_KEY } = process.env
31+
32+
assert(Boolean(ELASTICSEARCH_URL), "ELASTICSEARCH_URL is required")
33+
assert(Boolean(ES_API_SECRET_KEY), "ES_API_SECRET_KEY is required")
34+
35+
const client = new Client({
36+
node: ELASTICSEARCH_URL,
37+
auth: { apiKey: ES_API_SECRET_KEY },
38+
})
39+
40+
const indicesBefore = await client.cat.indices()
41+
assert.equal(indicesBefore.trim().length, 0, "There should not be any indices.")
42+
43+
await client.indices.create({
44+
index: 'books',
45+
aliases: { novels: {}, 'things_to_read': {} },
46+
})
47+
48+
const indicesDuring = await client.cat.indices()
49+
assert(indicesDuring.includes('books'), "Books index should exist")
50+
51+
const body = [
52+
{name: "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470},
53+
{name: "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585},
54+
{name: "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328},
55+
{name: "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227},
56+
{name: "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268},
57+
{name: "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
58+
]
59+
60+
let docCount = 0
61+
const bulkResult = await client.helpers.bulk({
62+
datasource: body,
63+
onDocument () {
64+
docCount++
65+
return {
66+
index: { _index: 'books' }
67+
}
68+
}
69+
})
70+
assert.equal(docCount, 6, "Docs indexed should be 6")
71+
assert.equal(bulkResult.total, 6, "Total docs indexed should be 6")
72+
assert.equal(bulkResult.failed, 0, "Total failed docs should be 0")
73+
assert.equal(bulkResult.successful, 6, "Total successful docs should be 6")
74+
75+
await client.indices.refresh({ index: 'books' })
76+
77+
const result = await client.search({
78+
index: 'things_to_read',
79+
query: {
80+
match: {
81+
author: 'Ray Bradbury'
82+
}
83+
}
84+
})
85+
assert.equal(result.hits.hits.length, 1)
86+
assert.equal(result.hits.hits[0]._source.name, "Fahrenheit 451")
87+
88+
const docId = result.hits.hits[0]._id
89+
const doc = await client.get({ index: 'novels', id: docId })
90+
91+
assert.equal(doc._source.author, "Ray Bradbury")
92+
93+
await client.update({ index: 'novels', id: docId, doc: { author: 'Ray Bradberry', 'rating': 3.2 }})
94+
await client.indices.refresh({ index: 'books' })
95+
96+
const doc2 = await client.get({ index: 'novels', id: docId })
97+
assert.equal(doc2._source.author, "Ray Bradberry")
98+
assert.equal(doc2._source.rating, 3.2)
99+
100+
await client.indices.delete({ index: 'books' })
101+
102+
const indicesAfter = await client.cat.indices()
103+
assert.equal(indicesAfter.trim().length, 0, "There should not be any indices.")
104+
}
105+
106+
main()
107+
.catch(err => console.error(err))
108+
.finally(() => console.log('Test succeeded'))

0 commit comments

Comments
 (0)