You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2025/09/10 13:08:00 UTC
(couchdb-nano) 01/01: make the library ESM-only. Exchange all "require"s for "import"s.
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch esm
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 8660583d871e1f97ff775286e7bf291c6f09b061
Author: Glynn Bird <gl...@apache.org>
AuthorDate: Wed Sep 10 11:04:40 2025 +0100
make the library ESM-only. Exchange all "require"s for "import"s.
---
README.md | 110 ++++++++++++++++--------------
lib/changesreader.js | 11 ++-
lib/cookie.js | 4 +-
lib/multipart.js | 3 +-
lib/nano.js | 22 +++---
package-lock.json | 4 +-
package.json | 3 +-
test/attachment.destroy.test.js | 8 +--
test/attachment.get.test.js | 8 +--
test/attachment.getAsStream.test.js | 8 +--
test/attachment.insert.test.js | 11 +--
test/cookie.test.js | 7 +-
test/database.changes.test.js | 8 +--
test/database.changesAsStream.test.js | 8 +--
test/database.compact.test.js | 8 +--
test/database.create.test.js | 8 +--
test/database.destroy.test.js | 8 +--
test/database.get.test.js | 9 ++-
test/database.list.test.js | 8 +--
test/database.listAsStream.test.js | 8 +--
test/database.replicate.test.js | 9 ++-
test/database.replication.disable.test.js | 9 ++-
test/database.replication.enable.test.js | 9 ++-
test/database.replication.query.test.js | 8 +--
test/design.atomic.test.js | 8 +--
test/design.createIndex.test.js | 8 +--
test/design.find.test.js | 8 +--
test/design.findAsStream.test.js | 8 +--
test/design.search.test.js | 8 +--
test/design.searchAsStream.test.js | 8 +--
test/design.show.test.js | 8 +--
test/design.view.test.js | 8 +--
test/design.viewAsStream.test.js | 8 +--
test/design.viewWithList.test.js | 8 +--
test/design.viewWithListAsStream.test.js | 8 +--
test/document.bulk.test.js | 8 +--
test/document.changesreader.test.js | 11 ++-
test/document.destroy.test.js | 8 +--
test/document.fetch.test.js | 8 +--
test/document.fetchRevs.test.js | 8 +--
test/document.get.test.js | 8 +--
test/document.head.test.js | 8 +--
test/document.insert.test.js | 8 +--
test/document.list.test.js | 8 +--
test/document.listAsStream.test.js | 8 +--
test/mock.js | 21 +++---
test/multipart.get.test.js | 8 +--
test/multipart.insert.test.js | 8 +--
test/multipart.test.js | 6 +-
test/nano.agent.test.js | 10 +--
test/nano.auth.test.js | 8 +--
test/nano.config.test.js | 6 +-
test/nano.customheaders.test.js | 8 +--
test/nano.info.test.js | 8 +--
test/nano.logger.test.js | 8 +--
test/nano.request.test.js | 8 +--
test/nano.session.test.js | 8 +--
test/nano.updates.test.js | 8 +--
test/nano.use.test.js | 6 +-
test/nano.uuids.test.js | 8 +--
test/notnocked.test.js | 6 +-
test/partition.find.test.js | 8 +--
test/partition.findAsStream.test.js | 8 +--
test/partition.info.test.js | 8 +--
test/partition.list.test.js | 8 +--
test/partition.listAsStream.test.js | 8 +--
test/partition.search.test.js | 8 +--
test/partition.searchAsStream.test.js | 8 +--
test/partition.view.test.js | 8 +--
test/partition.viewAsStream.test.js | 8 +--
70 files changed, 336 insertions(+), 341 deletions(-)
diff --git a/README.md b/README.md
index 2439615..365f370 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,8 @@ Offical [Apache CouchDB](https://couchdb.apache.org/) library for [Node.js](http
> Note: Nano >=11.0.0 is a **breaking change for Node.js versions 16 and older**. Nano 11 uses Node.js's built-in "fetch" HTTP client but this is only available in Node.js versions 18 or later. If you are using Node 16 or older then continue using Nano 10.
> See our [migration guide](migration_guide_v10_to_v11.md) for moving from Nano 10 to Nano 11.
+> Note: Nano >=12.0.0 is ESM-only, meaning that the `import` syntax is used to load the module instead of `require`.
+
Features:
* **Minimalistic** - There is only a minimum of abstraction between you and
@@ -26,7 +28,7 @@ or save `nano` as a dependency of your project with
npm install --save nano
-Note the minimum required version of Node.js is 10.
+Note the minimum required version of Node.js is 20.
## Table of contents
@@ -108,7 +110,8 @@ Note the minimum required version of Node.js is 10.
To use `nano` you need to connect it to your CouchDB install, to do that:
```js
-const nano = require('nano')('http://127.0.0.1:5984');
+import Nano from 'nano'
+const nano = Nano('http://127.0.0.1:5984')
```
> Note: Supplying authentication credentials in the URL e.g. `http://admin:mypassword@localhost:5984` is deprecated. Use `nano.auth` instead.
@@ -116,13 +119,13 @@ const nano = require('nano')('http://127.0.0.1:5984');
To create a new database:
```js
-nano.db.create('alice');
+nano.db.create('alice')
```
and to use an existing database:
```js
-const alice = nano.db.use('alice');
+const alice = nano.db.use('alice')
```
Under-the-hood, calls like `nano.db.create` are making HTTP API calls to the CouchDB service. Such operations are *asynchronous*. There are two ways to receive the asynchronous data back from the library
@@ -184,15 +187,16 @@ You can also see your document in futon (http://127.0.0.1:5984/_utils).
Configuring nano to use your database server is as simple as:
```js
-const nano = require('nano')('http://127.0.0.1:5984')
-const db = nano.use('foo');
+import Nano from 'nano'
+const nano = Nano('http://127.0.0.1:5984')
+const db = nano.use('foo')
```
If you don't need to instrument database objects you can simply:
```js
// nano parses the URL and knows this is a database
-const db = require('nano')('http://127.0.0.1:5984/foo');
+const db = Nano('http://127.0.0.1:5984/foo')
```
You can tell nano to not parse the URL (maybe the server is behind a proxy, is accessed through a rewrite rule or other):
@@ -200,12 +204,12 @@ You can tell nano to not parse the URL (maybe the server is behind a proxy, is a
```js
// nano does not parse the URL and return the server api
// "http://127.0.0.1:5984/prefix" is the CouchDB server root
-const couch = require('nano')(
+const couch = Nano(
{
url : "http://127.0.0.1:5984/prefix"
parseUrl : false
- });
-const db = couch.use('foo');
+ })
+const db = couch.use('foo')
```
### Pool size and open sockets
@@ -213,6 +217,8 @@ const db = couch.use('foo');
To specify the number of connections, timeouts and pool size, supply an `agentOptions` object when starting up Nano.
```js
+import Nano from 'nano'
+import undici from 'undici'
const agentOptions = {
bodyTimeout: 30000,
headersTimeout: 30000,
@@ -229,7 +235,6 @@ const agentOptions = {
connections: null,
maxRedirections: 0
}
-const undici = require('undici')
const undiciOptions = new undici.Agent(agentOptions)
const nano = Nano({ url: 'http://127.0.0.1:5984', undiciOptions })
```
@@ -251,13 +256,13 @@ To supply customer headers with each request, supply a headers object when start
```js
-const couch = require('nano')(
+const couch = Nano(
{
url : "http://127.0.0.1:5984/prefix"
headers: {
mycustomheader: '42'
}
- });
+ })
```
## TypeScript
@@ -344,7 +349,7 @@ Lists all the CouchDB databases as a stream:
```js
nano.db.listAsStream()
.on('error', (e) => console.error('error', e))
- .pipe(process.stdout);
+ .pipe(process.stdout)
```
### nano.db.compact(name, [designname])
@@ -396,7 +401,7 @@ by the call to `replication.enable`:
const r = await nano.db.replication.enable('alice',
'http://admin:password@otherhost.com:5984/alice',
{ create_target:true })
-await nano.db.replication.disable(r.id);
+await nano.db.replication.disable(r.id)
```
### nano.db.changes(name, [params])
@@ -413,7 +418,7 @@ const c = await nano.db.changes('alice')
Same as `nano.db.changes` but returns a stream.
```js
-nano.db.changes('alice').pipe(process.stdout);
+nano.db.changes('alice').pipe(process.stdout)
```
### nano.db.info()
@@ -429,7 +434,7 @@ const info = await nano.db.info()
Returns a database object that allows you to perform operations against that database:
```js
-const alice = nano.use('alice');
+const alice = nano.use('alice')
await alice.insert({ happy: true }, 'rabbit')
```
@@ -505,7 +510,7 @@ The response is an object with [CouchDB cluster information](https://docs.couchd
Inserts `doc` in the database with optional `params`. If params is a string, it's assumed it is the intended document `_id`. If params is an object, it's passed as query string parameters and `docName` is checked for defining the document `_id`:
```js
-const alice = nano.use('alice');
+const alice = nano.use('alice')
const response = await alice.insert({ happy: true }, 'rabbit')
```
@@ -570,7 +575,7 @@ Bulk operations(update/delete/insert) on the database, refer to the
const documents = [
{ a:1, b:2 },
{ _id: 'tiger', striped: true}
-];
+]
const response = await alice.bulk({ docs: documents })
```
@@ -581,9 +586,9 @@ List all the docs in the database .
```js
const doclist = await alice.list().then((body)=>{
body.rows.forEach((doc) => {
- console.log(doc);
+ console.log(doc)
})
-});
+})
```
or with optional query string additions `params`:
@@ -610,7 +615,7 @@ additional query string `params` can be specified, `include_docs` is always set
to `true`.
```js
-const keys = ['tiger', 'zebra', 'donkey'];
+const keys = ['tiger', 'zebra', 'donkey']
const datat = await alice.fetch({keys: keys})
```
@@ -632,7 +637,7 @@ Create index on database fields, as specified in
const indexDef = {
index: { fields: ['foo'] },
name: 'fooindex'
-};
+}
const response = await alice.createIndex(indexDef)
```
@@ -656,11 +661,11 @@ const db = nano.db.use('mydb')
db.changesReader.start()
.on('change', (change) => { console.log(change) })
.on('batch', (b) => {
- console.log('a batch of', b.length, 'changes has arrived');
+ console.log('a batch of', b.length, 'changes has arrived')
}).on('seq', (s) => {
- console.log('sequence token', s);
+ console.log('sequence token', s)
}).on('error', (e) => {
- console.error('error', e);
+ console.error('error', e)
})
```
@@ -671,7 +676,7 @@ If you want `changesReader` to hold off making the next `_changes` API call unti
```js
db.changesReader.get({wait: true})
.on('batch', (b) => {
- console.log('a batch of', b.length, 'changes has arrived');
+ console.log('a batch of', b.length, 'changes has arrived')
// do some asynchronous work here and call "changesReader.resume()"
// when you're ready for the next API call to be dispatched.
// In this case, wait 5s before the next changes feed request.
@@ -679,8 +684,8 @@ db.changesReader.get({wait: true})
db.changesReader.resume()
}, 5000)
}).on('end', () => {
- console.log('changes feed monitoring has stopped');
- });
+ console.log('changes feed monitoring has stopped')
+ })
```
You may supply a number of options when you start to listen to the changes feed:
@@ -947,13 +952,13 @@ Inserts a `doc` together with `attachments` and `params`. If params is a string,
The `attachments` parameter must be an array of objects with `name`, `data` and `content_type` properties.
```js
-const fs = require('fs');
+import fs from 'node:fs'
fs.readFile('rabbit.png', (err, data) => {
if (!err) {
await alice.multipart.insert({ foo: 'bar' }, [{name: 'rabbit.png', data: data, content_type: 'image/png'}], 'mydoc')
}
-});
+})
```
### db.multipart.get(docname, [params])
@@ -973,7 +978,7 @@ Inserts an attachment `attname` to `docname`, in most cases
[CouchDB doc](https://docs.couchdb.org/en/latest/api/document/attachments.html#db-doc-attachment) for more details.
```js
-const fs = require('fs');
+import fs from 'node:fs'
fs.readFile('rabbit.png', (err, data) => {
if (!err) {
@@ -983,7 +988,7 @@ fs.readFile('rabbit.png', (err, data) => {
'image/png',
{ rev: '12-150985a725ec88be471921a54ce91452' })
}
-});
+})
```
### db.attachment.insertAsStream(docname, attname, att, contenttype, [params])
@@ -997,7 +1002,7 @@ Get `docname`'s attachment `attname` with optional query string additions
`params`.
```js
-const fs = require('fs');
+import fs from 'node:fs'
const body = await alice.attachment.get('rabbit', 'rabbit.png')
fs.writeFile('rabbit.png', body)
@@ -1006,10 +1011,10 @@ fs.writeFile('rabbit.png', body)
### db.attachment.getAsStream(docname, attname, [params])
```js
-const fs = require('fs');
+import fs from 'node:fs'
alice.attachment.getAsStream('rabbit', 'rabbit.png')
.on('error', e => console.error)
- .pipe(fs.createWriteStream('rabbit.png'));
+ .pipe(fs.createWriteStream('rabbit.png'))
```
### db.attachment.destroy(docname, attname, [params])
@@ -1059,7 +1064,7 @@ Same as `db.view` but returns a stream:
```js
alice.viewAsStream('characters', 'happy_ones', {reduce: false})
.on('error', (e) => console.error('error', e))
- .pipe(process.stdout);
+ .pipe(process.stdout)
```
### db.viewWithList(designname, viewname, listname, [params])
@@ -1077,7 +1082,7 @@ Calls a list function fed by the given view from the specified design document a
```js
alice.viewWithListAsStream('characters', 'happy_ones', 'my_list')
.on('error', (e) => console.error('error', e))
- .pipe(process.stdout);
+ .pipe(process.stdout)
```
### db.show(designname, showname, doc_id, [params])
@@ -1138,7 +1143,7 @@ Check out the tests for a fully functioning example.
Calls a view of the specified design with optional query string additions `params`. Returns stream.
```js
-alice.search('characters', 'happy_ones', { q: 'cat' }).pipe(process.stdout);
+alice.search('characters', 'happy_ones', { q: 'cat' }).pipe(process.stdout)
```
### db.find(selector)
@@ -1154,7 +1159,7 @@ const q = {
},
fields: [ "name", "age", "tags", "url" ],
limit:50
-};
+}
const response = await alice.find(q)
```
@@ -1171,10 +1176,10 @@ const q = {
},
fields: [ "name", "age", "tags", "url" ],
limit:50
-};
+}
alice.findAsStream(q)
.on('error', (e) => console.error('error', e))
- .pipe(process.stdout);
+ .pipe(process.stdout)
```
## using cookie authentication
@@ -1182,7 +1187,8 @@ alice.findAsStream(q)
Nano supports making requests using CouchDB's [cookie authentication](http://guide.couchdb.org/editions/1/en/security.html#cookies) functionality. If you initialise *Nano* so that it is cookie-aware, you may call `nano.auth` first to get a session cookie. Nano will behave like a web browser, remembering your session cookie and refreshing it if a new one is received in a future HTTP response.
```js
-const nano = require('nano')({
+import Nano from 'nano'
+const nano = Nano({
url: 'http://127.0.0.1:5984'
})
const username = 'user'
@@ -1237,12 +1243,12 @@ function getrabbitrev(rev) {
doc: 'rabbit',
method: 'get',
params: { rev: rev }
- });
+ })
}
getrabbitrev('4-2e6cdc4c7e26b745c2881a24e0eeece2').then((body) => {
- console.log(body);
-});
+ console.log(body)
+})
```
### Pipes
@@ -1250,12 +1256,13 @@ getrabbitrev('4-2e6cdc4c7e26b745c2881a24e0eeece2').then((body) => {
You can pipe the return values of certain nano functions like other stream. For example if our `rabbit` document has an attachment with name `picture.png` you can pipe it to a `writable stream`:
```js
-const fs = require('fs');
-const nano = require('nano')('http://127.0.0.1:5984/');
-const alice = nano.use('alice');
+import fs from 'node:fs'
+import Nano from 'nano'
+const nano = Nano('http://127.0.0.1:5984/')
+const alice = nano.use('alice')
alice.attachment.getAsStream('rabbit', 'picture.png')
.on('error', (e) => console.error('error', e))
- .pipe(fs.createWriteStream('/tmp/rabbit.png'));
+ .pipe(fs.createWriteStream('/tmp/rabbit.png'))
```
then open `/tmp/rabbit.png` and you will see the rabbit picture.
@@ -1285,13 +1292,12 @@ const nano = Nano({ url: process.env.COUCH_URL, log: console.log })
You may supply your own logging function to format the data before output:
```js
-const url = require('url')
const logger = (data) => {
// only output logging if there is an environment variable set
if (process.env.LOG === 'nano') {
// if this is a request
if (typeof data.err === 'undefined') {
- const u = new url.URL(data.uri)
+ const u = new URL(data.uri)
console.log(data.method, u.pathname, data.qs)
} else {
// this is a response
diff --git a/lib/changesreader.js b/lib/changesreader.js
index 98ca422..1e3f51f 100644
--- a/lib/changesreader.js
+++ b/lib/changesreader.js
@@ -1,13 +1,13 @@
-const EventEmitter = require('events').EventEmitter
+import EventEmitter from 'node:events'
+import stream from 'node:stream'
const AbortController = global.AbortController
-const stream = require('stream')
const EVENT_BATCH = 'batch'
const EVENT_CHANGE = 'change'
const EVENT_SEQ = 'seq'
const EVENT_ERROR = 'error'
// streaming line breaker
-const liner = () => {
+function liner() {
const liner = new stream.Transform({ objectMode: true })
liner._transform = function (chunk, encoding, done) {
@@ -33,7 +33,7 @@ const liner = () => {
}
// streaming change processor
-const changeProcessor = (ee, batchSize) => {
+function changeProcessor(ee, batchSize) {
const changeProcessor = new stream.Transform({ objectMode: true })
const buffer = []
changeProcessor.lastSeq = '0'
@@ -81,7 +81,7 @@ const changeProcessor = (ee, batchSize) => {
* @param {String} db - Name of the database.
* @param {Function} request - Nano.relax
*/
-class ChangesReader {
+export default class ChangesReader {
// constructor
constructor (db, request) {
this.db = db
@@ -295,4 +295,3 @@ class ChangesReader {
}
}
-module.exports = ChangesReader
diff --git a/lib/cookie.js b/lib/cookie.js
index d18a4ce..534f345 100644
--- a/lib/cookie.js
+++ b/lib/cookie.js
@@ -1,7 +1,6 @@
-const { URL } = require('url')
// a simple cookie jar
-class CookieJar {
+export default class CookieJar {
// create new empty cookie jar
constructor () {
this.jar = []
@@ -126,4 +125,3 @@ class CookieJar {
}
}
-module.exports = CookieJar
diff --git a/lib/multipart.js b/lib/multipart.js
index cf7f946..ee4e56b 100644
--- a/lib/multipart.js
+++ b/lib/multipart.js
@@ -4,7 +4,7 @@ const DASHES = '--'
// generate the payload, boundary and header for a multipart/related request
// to upload binary attachments to CouchDB.
// https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
-class MultiPartFactory {
+export default class MultiPartFactory {
// constructor
constructor (parts) {
// generate a unique id that forms the boundary between parts
@@ -50,4 +50,3 @@ class MultiPartFactory {
}
}
-module.exports = MultiPartFactory
diff --git a/lib/nano.js b/lib/nano.js
index c7bbda2..c1facb3 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -10,14 +10,14 @@
// License for the specific language governing permissions and limitations under
// the License.
-const { URL } = require('url')
-const assert = require('assert')
-const stream = require('stream')
-const Readable = stream.Readable
-const ChangesReader = require('./changesreader.js')
-const CookieJar = require('./cookie.js')
-const MultiPartFactory = require('./multipart.js')
-const pkg = require('../package.json')
+import assert from 'node:assert'
+import { PassThrough, Readable } from 'node:stream'
+import ChangesReader from './changesreader.js'
+import CookieJar from './cookie.js'
+import MultiPartFactory from './multipart.js'
+import fs from 'node:fs'
+import path from 'node:path'
+const pkg = JSON.parse(fs.readFileSync(path.join(import.meta.dirname, '..', 'package.json'), { encoding: 'utf8' }))
const SCRUBBED_STR = 'XXXXXX'
@@ -34,7 +34,7 @@ function missing (...params) {
// the stock error returned when a call has missing or invalid parameters
const invalidParametersError = new Error('Invalid parameters')
-module.exports = exports = function dbScope (cfg) {
+export default function Nano (cfg) {
let serverScope = {}
if (typeof cfg === 'string') {
@@ -396,7 +396,7 @@ module.exports = exports = function dbScope (cfg) {
}
// if the body is readable stream
- if (fetchOptions.body && fetchOptions.body instanceof stream.Readable) {
+ if (fetchOptions.body && fetchOptions.body instanceof Readable) {
fetchOptions.duplex = 'half'
fetchOptions.keepalive = false
}
@@ -410,7 +410,7 @@ module.exports = exports = function dbScope (cfg) {
// actually do the HTTP request
if (opts.stream) {
// return the Request object for streaming
- const outStream = new stream.PassThrough()
+ const outStream = new PassThrough()
fetch(fetchOptions.url, fetchOptions).then((response) => {
const readableWebStream = response.body
const readableNodeStream = Readable.fromWeb ? Readable.fromWeb(readableWebStream) : Readable.from(readableWebStream)
diff --git a/package-lock.json b/package-lock.json
index 2080ecd..88b5a29 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "nano",
- "version": "11.0.0",
+ "version": "12.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "nano",
- "version": "11.0.0",
+ "version": "12.0.0",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^24.3.0",
diff --git a/package.json b/package.json
index fc0a36d..a7c17b9 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,11 @@
{
"name": "nano",
"description": "The official CouchDB client for Node.js",
+ "type": "module",
"license": "Apache-2.0",
"homepage": "http://github.com/apache/couchdb-nano",
"repository": "http://github.com/apache/couchdb-nano",
- "version": "11.0.0",
+ "version": "12.0.0",
"author": "Apache CouchDB <de...@couchdb.apache.org> (http://couchdb.apache.org)",
"keywords": [
"couchdb",
diff --git a/test/attachment.destroy.test.js b/test/attachment.destroy.test.js
index bb5bbf2..6dbc9c0 100644
--- a/test/attachment.destroy.test.js
+++ b/test/attachment.destroy.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to destroy an attachment - DELETE /db/id/attname - db.attachment.destroy', async () => {
diff --git a/test/attachment.get.test.js b/test/attachment.get.test.js
index fcb70c4..c2e1ed8 100644
--- a/test/attachment.get.test.js
+++ b/test/attachment.get.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
diff --git a/test/attachment.getAsStream.test.js b/test/attachment.getAsStream.test.js
index 35909b8..f623485 100644
--- a/test/attachment.getAsStream.test.js
+++ b/test/attachment.getAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
diff --git a/test/attachment.insert.test.js b/test/attachment.insert.test.js
index af9c9ec..4de7aef 100644
--- a/test/attachment.insert.test.js
+++ b/test/attachment.insert.test.js
@@ -10,12 +10,13 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import fs from 'node:fs'
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
+
const nano = Nano(COUCH_URL)
-const fs = require('fs')
const image = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64')
test('should be able to insert document attachment - PUT /db/docname/attachment - db.attachment.insert', async () => {
diff --git a/test/cookie.test.js b/test/cookie.test.js
index 32ba062..8a9fd0f 100644
--- a/test/cookie.test.js
+++ b/test/cookie.test.js
@@ -10,10 +10,9 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-
-const CookieJar = require('../lib/cookie.js')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import CookieJar from '../lib/cookie.js'
test('should parse cookies correctly', () => {
const cj = new CookieJar()
diff --git a/test/database.changes.test.js b/test/database.changes.test.js
index 44506b8..ea74f57 100644
--- a/test/database.changes.test.js
+++ b/test/database.changes.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
diff --git a/test/database.changesAsStream.test.js b/test/database.changesAsStream.test.js
index 149f3af..ae965df 100644
--- a/test/database.changesAsStream.test.js
+++ b/test/database.changesAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
results: [
diff --git a/test/database.compact.test.js b/test/database.compact.test.js
index 38c7a8f..61663b8 100644
--- a/test/database.compact.test.js
+++ b/test/database.compact.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = { ok: true }
diff --git a/test/database.create.test.js b/test/database.create.test.js
index fef1795..d4c5b86 100644
--- a/test/database.create.test.js
+++ b/test/database.create.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = { ok: true }
diff --git a/test/database.destroy.test.js b/test/database.destroy.test.js
index 835d057..403c553 100644
--- a/test/database.destroy.test.js
+++ b/test/database.destroy.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = { ok: true }
diff --git a/test/database.get.test.js b/test/database.get.test.js
index 290834e..88f031a 100644
--- a/test/database.get.test.js
+++ b/test/database.get.test.js
@@ -10,11 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
db_name: 'db',
diff --git a/test/database.list.test.js b/test/database.list.test.js
index 6c670da..fb54c4b 100644
--- a/test/database.list.test.js
+++ b/test/database.list.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = ['rita', 'sue', 'bob']
diff --git a/test/database.listAsStream.test.js b/test/database.listAsStream.test.js
index f8525d5..c83150f 100644
--- a/test/database.listAsStream.test.js
+++ b/test/database.listAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = ['rita', 'sue', 'bob']
diff --git a/test/database.replicate.test.js b/test/database.replicate.test.js
index 14d332b..d287df6 100644
--- a/test/database.replicate.test.js
+++ b/test/database.replicate.test.js
@@ -10,11 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
history: [],
diff --git a/test/database.replication.disable.test.js b/test/database.replication.disable.test.js
index 04e1f9b..ca88df9 100644
--- a/test/database.replication.disable.test.js
+++ b/test/database.replication.disable.test.js
@@ -10,11 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = { ok: true, id: 'rep1', rev: '2-123' }
const errResponse = {
diff --git a/test/database.replication.enable.test.js b/test/database.replication.enable.test.js
index 38b64bc..f7f6c27 100644
--- a/test/database.replication.enable.test.js
+++ b/test/database.replication.enable.test.js
@@ -10,11 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = { ok: true, id: 'abc', rev: '1-123' }
diff --git a/test/database.replication.query.test.js b/test/database.replication.query.test.js
index e15d016..d84150c 100644
--- a/test/database.replication.query.test.js
+++ b/test/database.replication.query.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
_id: 'rep1',
diff --git a/test/design.atomic.test.js b/test/design.atomic.test.js
index a471b7b..f29ffbe 100644
--- a/test/design.atomic.test.js
+++ b/test/design.atomic.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to use an update function - PUT /db/_design/ddoc/_update/updatename/docid - db.atomic', async () => {
diff --git a/test/design.createIndex.test.js b/test/design.createIndex.test.js
index 4802863..ba9dd21 100644
--- a/test/design.createIndex.test.js
+++ b/test/design.createIndex.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to create an index - POST /db/_index - db.createIndex', async () => {
diff --git a/test/design.find.test.js b/test/design.find.test.js
index 0789582..563ea37 100644
--- a/test/design.find.test.js
+++ b/test/design.find.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to query an index - POST /db/_find - db.find', async () => {
diff --git a/test/design.findAsStream.test.js b/test/design.findAsStream.test.js
index 3a317ce..406a091 100644
--- a/test/design.findAsStream.test.js
+++ b/test/design.findAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to query an index as a stream- POST /db/_find - db.findAsStream', async () => {
diff --git a/test/design.search.test.js b/test/design.search.test.js
index ac02f85..443241d 100644
--- a/test/design.search.test.js
+++ b/test/design.search.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a search index - POST /db/_design/ddoc/_search/searchname - db.search', async () => {
diff --git a/test/design.searchAsStream.test.js b/test/design.searchAsStream.test.js
index 0d1348f..4df4433 100644
--- a/test/design.searchAsStream.test.js
+++ b/test/design.searchAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a search index as a stream - POST /db/_design/ddoc/_search/searchname - db.searchAsStream', async () => {
diff --git a/test/design.show.test.js b/test/design.show.test.js
index 90d6847..2336825 100644
--- a/test/design.show.test.js
+++ b/test/design.show.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to use a show function - GET /db/_design/ddoc/_show/showname/docid - db.show', async () => {
diff --git a/test/design.view.test.js b/test/design.view.test.js
index a36f24a..4dd347c 100644
--- a/test/design.view.test.js
+++ b/test/design.view.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a MapReduce view - GET /db/_design/ddoc/_view/viewname - db.view', async () => {
diff --git a/test/design.viewAsStream.test.js b/test/design.viewAsStream.test.js
index 44ac2aa..af25ac5 100644
--- a/test/design.viewAsStream.test.js
+++ b/test/design.viewAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a MapReduce view as a stream - GET /db/_design/ddoc/_view/viewname - db.viewAsStream', async () => {
diff --git a/test/design.viewWithList.test.js b/test/design.viewWithList.test.js
index 07d48bc..9847ea0 100644
--- a/test/design.viewWithList.test.js
+++ b/test/design.viewWithList.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a MapReduce view with a list - GET /db/_design/ddoc/_list/listname/viewname - db.viewWithList', async () => {
diff --git a/test/design.viewWithListAsStream.test.js b/test/design.viewWithListAsStream.test.js
index 053b739..94b6ae3 100644
--- a/test/design.viewWithListAsStream.test.js
+++ b/test/design.viewWithListAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a MapReduce view with a list as a stream - GET /db/_design/ddoc/_list/listname/viewname - db.viewWithListAsStream', async () => {
diff --git a/test/document.bulk.test.js b/test/document.bulk.test.js
index 237b395..217a693 100644
--- a/test/document.bulk.test.js
+++ b/test/document.bulk.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to insert documents in bulk - POST /db/_bulk_docs - db.bulk', async () => {
diff --git a/test/document.changesreader.test.js b/test/document.changesreader.test.js
index f22a947..d454a8a 100644
--- a/test/document.changesreader.test.js
+++ b/test/document.changesreader.test.js
@@ -10,10 +10,11 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import fs from 'node:fs'
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const DBNAME = 'db'
@@ -206,7 +207,6 @@ test('should keep polling the changes feed (wait: true) - db.changesReader.start
})
test('spooling changes - db.changesReader.spool', async () => {
- const fs = require('fs')
const reply = fs.readFileSync('./test/changes.json')
const replyObj = JSON.parse(reply)
mockPool
@@ -229,7 +229,6 @@ test('spooling changes - db.changesReader.spool', async () => {
})
test('spooling changes - numeric seq - db.changesReader.spool', async () => {
- const fs = require('fs')
const reply = fs.readFileSync('./test/changes_numeric.json')
const replyObj = JSON.parse(reply)
mockPool
diff --git a/test/document.destroy.test.js b/test/document.destroy.test.js
index 82f2d3f..d3c7d15 100644
--- a/test/document.destroy.test.js
+++ b/test/document.destroy.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to destroy a document - DELETE /db/id - db.destroy', async () => {
diff --git a/test/document.fetch.test.js b/test/document.fetch.test.js
index 97df61f..d2ddfee 100644
--- a/test/document.fetch.test.js
+++ b/test/document.fetch.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano({ url: COUCH_URL })
test('should be able to fetch a list of documents - POST /db/_all_docs - db.fetch', async () => {
diff --git a/test/document.fetchRevs.test.js b/test/document.fetchRevs.test.js
index 5d5771d..abd8b2e 100644
--- a/test/document.fetchRevs.test.js
+++ b/test/document.fetchRevs.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to fetch a list of document revisions - POST /db/_all_docs - db.fetchRevs', async () => {
diff --git a/test/document.get.test.js b/test/document.get.test.js
index 1babced..6f87aa8 100644
--- a/test/document.get.test.js
+++ b/test/document.get.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to get a document - GET /db/id - db.get', async () => {
diff --git a/test/document.head.test.js b/test/document.head.test.js
index 70941ce..595055c 100644
--- a/test/document.head.test.js
+++ b/test/document.head.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to head a document - HEAD /db/id - db.head', async () => {
diff --git a/test/document.insert.test.js b/test/document.insert.test.js
index 6895a2f..d6a7a61 100644
--- a/test/document.insert.test.js
+++ b/test/document.insert.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to insert document - POST /db - db.insert', async () => {
diff --git a/test/document.list.test.js b/test/document.list.test.js
index 175d460..04bbb2a 100644
--- a/test/document.list.test.js
+++ b/test/document.list.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to get a list of documents - GET /db/_all_docs - db.list', async () => {
diff --git a/test/document.listAsStream.test.js b/test/document.listAsStream.test.js
index e3590f6..45cf647 100644
--- a/test/document.listAsStream.test.js
+++ b/test/document.listAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should get a streamed list of documents - GET /db/_all_docs - db.listAsStream', async () => {
diff --git a/test/mock.js b/test/mock.js
index d793f95..3ef4e2c 100644
--- a/test/mock.js
+++ b/test/mock.js
@@ -1,14 +1,11 @@
-const COUCH_URL = 'http://127.0.0.1:5984'
-const JSON_HEADERS = { headers: { 'content-type': 'application/json' } }
-const { MockAgent, setGlobalDispatcher } = require('undici')
-const mockAgent = new MockAgent()
+import { MockAgent, setGlobalDispatcher } from 'undici'
+
+export const mockAgent = new MockAgent()
mockAgent.disableNetConnect()
-const mockPool = mockAgent.get(COUCH_URL)
-setGlobalDispatcher(mockAgent)
-module.exports = {
- COUCH_URL,
- JSON_HEADERS,
- mockAgent,
- mockPool
-}
+
+
+export const COUCH_URL = 'http://127.0.0.1:5984'
+export const JSON_HEADERS = { headers: { 'content-type': 'application/json' } }
+export const mockPool = mockAgent.get(COUCH_URL)
+setGlobalDispatcher(mockAgent)
diff --git a/test/multipart.get.test.js b/test/multipart.get.test.js
index 5b6056a..31f0183 100644
--- a/test/multipart.get.test.js
+++ b/test/multipart.get.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const multipartResponse = ''.concat(
diff --git a/test/multipart.insert.test.js b/test/multipart.insert.test.js
index 38dce82..26777d5 100644
--- a/test/multipart.insert.test.js
+++ b/test/multipart.insert.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const image1 = Buffer.from(''.concat(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAsV',
diff --git a/test/multipart.test.js b/test/multipart.test.js
index 32d0870..a670603 100644
--- a/test/multipart.test.js
+++ b/test/multipart.test.js
@@ -1,6 +1,6 @@
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const MultiPartFactory = require('../lib/multipart.js')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import MultiPartFactory from '../lib/multipart.js'
const textAttachment = { name: 'test.txt', data: 'Hello\r\nWorld!', content_type: 'text/plain' }
const anotherTextAttachment = { name: 'test2.txt', data: 'the quick brown fox', content_type: 'text/plain' }
diff --git a/test/nano.agent.test.js b/test/nano.agent.test.js
index a124b0d..29eb543 100644
--- a/test/nano.agent.test.js
+++ b/test/nano.agent.test.js
@@ -1,8 +1,8 @@
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent } = require('./mock.js')
-const Nano = require('../lib/nano')
-const undici = require('undici')
+import undici from 'undici'
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent } from './mock.js'
+import Nano from '../lib/nano.js'
test('should be able to supply a custom agent parameters', async () => {
const agentOptions = {
diff --git a/test/nano.auth.test.js b/test/nano.auth.test.js
index 2e5cd3b..f11a8e7 100644
--- a/test/nano.auth.test.js
+++ b/test/nano.auth.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano({ url: COUCH_URL })
test('should be able to authenticate - POST /_session - nano.auth', async () => {
diff --git a/test/nano.config.test.js b/test/nano.config.test.js
index 3209dd7..0dbb929 100644
--- a/test/nano.config.test.js
+++ b/test/nano.config.test.js
@@ -10,9 +10,9 @@
// License for the specific language governing permissions and limitations under
// the License.
-const Nano = require('..')
-const test = require('node:test')
-const assert = require('node:assert/strict')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import Nano from '../lib/nano.js'
test('should be able to supply HTTP url - nano.config', () => {
const HTTP_URL = 'http://127.0.0.1:5984'
diff --git a/test/nano.customheaders.test.js b/test/nano.customheaders.test.js
index 38131f8..c307942 100644
--- a/test/nano.customheaders.test.js
+++ b/test/nano.customheaders.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const CUSTOM_HEADER = 'thequickbrownfox'
const nano = Nano({
url: COUCH_URL,
diff --git a/test/nano.info.test.js b/test/nano.info.test.js
index 1e97dff..cedfb58 100644
--- a/test/nano.info.test.js
+++ b/test/nano.info.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('../lib/nano')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to get info - GET / - nano.info', async () => {
diff --git a/test/nano.logger.test.js b/test/nano.logger.test.js
index 1db53c7..8a37678 100644
--- a/test/nano.logger.test.js
+++ b/test/nano.logger.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
test('should be able to log output with user-defined function', async () => {
// setup Nano with custom logger
diff --git a/test/nano.request.test.js b/test/nano.request.test.js
index 02954a6..3f30388 100644
--- a/test/nano.request.test.js
+++ b/test/nano.request.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano({ url: COUCH_URL })
test('check request can do GET requests - nano.request', async () => {
diff --git a/test/nano.session.test.js b/test/nano.session.test.js
index 7190834..e207c8b 100644
--- a/test/nano.session.test.js
+++ b/test/nano.session.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to check your session - GET /_session - nano.auth', async () => {
diff --git a/test/nano.updates.test.js b/test/nano.updates.test.js
index 7058fa4..74f2e2f 100644
--- a/test/nano.updates.test.js
+++ b/test/nano.updates.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const response = {
diff --git a/test/nano.use.test.js b/test/nano.use.test.js
index d867bbd..cd9d397 100644
--- a/test/nano.use.test.js
+++ b/test/nano.use.test.js
@@ -10,9 +10,9 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import Nano from '../lib/nano.js'
const nano = Nano('http://myurl.com')
test('should be able to use a database - nano.db.use', () => {
diff --git a/test/nano.uuids.test.js b/test/nano.uuids.test.js
index 26ffb2d..9eb4843 100644
--- a/test/nano.uuids.test.js
+++ b/test/nano.uuids.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to fetch uuids - GET /_uuids - nano.uuids', async () => {
diff --git a/test/notnocked.test.js b/test/notnocked.test.js
index f017d2f..43444aa 100644
--- a/test/notnocked.test.js
+++ b/test/notnocked.test.js
@@ -10,9 +10,9 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import Nano from '../lib/nano.js'
const COUCH_URL = 'http://admin:admin@127.0.0.1:5984'
const nano = Nano(COUCH_URL)
const dbName = 'notnocked' + new Date().getTime()
diff --git a/test/partition.find.test.js b/test/partition.find.test.js
index 8604307..9a9a3f1 100644
--- a/test/partition.find.test.js
+++ b/test/partition.find.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to query a partitioned index - POST /db/_partition/partition/_find - db.partitionedFind', async () => {
diff --git a/test/partition.findAsStream.test.js b/test/partition.findAsStream.test.js
index 4df1748..09182d0 100644
--- a/test/partition.findAsStream.test.js
+++ b/test/partition.findAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should get a queried streamed list of documents from a partition- POST /db/_partition/partition/_find - db.partitionedFindAsStream', async () => {
diff --git a/test/partition.info.test.js b/test/partition.info.test.js
index 5724aae..59160fe 100644
--- a/test/partition.info.test.js
+++ b/test/partition.info.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const db = nano.db.use('db')
diff --git a/test/partition.list.test.js b/test/partition.list.test.js
index 4bb52d3..05a31e8 100644
--- a/test/partition.list.test.js
+++ b/test/partition.list.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
const db = nano.db.use('db')
diff --git a/test/partition.listAsStream.test.js b/test/partition.listAsStream.test.js
index 9313fa1..670e291 100644
--- a/test/partition.listAsStream.test.js
+++ b/test/partition.listAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should get a streamed list of documents from a partition- GET /db/_partition/partition/_all_docs - db.partitionedListAsStream', async () => {
diff --git a/test/partition.search.test.js b/test/partition.search.test.js
index 1de358a..00b2c54 100644
--- a/test/partition.search.test.js
+++ b/test/partition.search.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a partitioned search index - GET /db/_partition/partition/_design/ddoc/_search/searchname - db.partitionedSearch', async () => {
diff --git a/test/partition.searchAsStream.test.js b/test/partition.searchAsStream.test.js
index f53a724..7753c53 100644
--- a/test/partition.searchAsStream.test.js
+++ b/test/partition.searchAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should get a searched streamed list of documents from a partition- GET /db/_partition/partition/_design/ddoc/_search/searchname - db.partitionedSearchAsStream', async () => {
diff --git a/test/partition.view.test.js b/test/partition.view.test.js
index a6fd0c0..79bf6d9 100644
--- a/test/partition.view.test.js
+++ b/test/partition.view.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should be able to access a partitioned view index - GET /db/_partition/partition/_design/ddoc/_view/viewname - db.partitionedView', async () => {
diff --git a/test/partition.viewAsStream.test.js b/test/partition.viewAsStream.test.js
index 1b15805..5ccbfc0 100644
--- a/test/partition.viewAsStream.test.js
+++ b/test/partition.viewAsStream.test.js
@@ -10,10 +10,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-const test = require('node:test')
-const assert = require('node:assert/strict')
-const { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } = require('./mock.js')
-const Nano = require('..')
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { COUCH_URL, mockAgent, mockPool, JSON_HEADERS } from './mock.js'
+import Nano from '../lib/nano.js'
const nano = Nano(COUCH_URL)
test('should get a streamed list of documents from a view from partition - GET /db/_partition/partition/_design/ddoc/_view/viewname - db.partitionedViewAsStream', async () => {