Skip to content

Commit 6918612

Browse files
committed
build(test): switch from required to imports in test modules
1 parent c36edc2 commit 6918612

27 files changed

+261
-318
lines changed

.eslintrc.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ module.exports = {
2020
},
2121
'plugins': ['header'],
2222
'extends': ['plugin:import/recommended'],
23+
'settings': {
24+
'import/resolver': {
25+
'node': {
26+
'extensions': ['.ts', '.js', '.mjs'],
27+
},
28+
},
29+
},
2330
'rules': {
2431
'header/header': [
2532
2,
@@ -110,44 +117,18 @@ module.exports = {
110117
'extends': ['plugin:jest/recommended', 'plugin:jest/style'],
111118
},
112119
{
113-
'files': ['test/**/*.test.js'],
120+
'files': ['test/**/*.test.js', 'test/**/*.test.mjs'],
114121
'rules': {
122+
'import/namespace': 'off',
115123
'jest/expect-expect': 'off',
116124
'jest/no-conditional-expect': 'off',
117125
'jest/no-done-callback': 'off',
118-
'jest/no-standalone-expect': 'off',
119-
'jest/no-try-expect': 'off',
120126
},
121127
},
122128
{
123129
'files': ['test/**/cloudant.v1.test.js'],
124130
'rules': {
125131
'prettier/prettier': 'off',
126-
'object-shorthand': 'off',
127-
},
128-
},
129-
{
130-
'files': [
131-
'test/**/readme.integration.test.js',
132-
'test/examples/src/ts/*.ts',
133-
],
134-
'rules': {
135-
'no-console': 'off',
136-
},
137-
},
138-
{
139-
'files': ['test/examples/src/js/*.js'],
140-
'rules': {
141-
'dot-notation': 'off',
142-
},
143-
},
144-
{
145-
'files': [
146-
'test/examples/src/js/CreateDbAndDoc.js',
147-
'test/examples/src/ts/CreateDbAndDoc.ts',
148-
],
149-
'rules': {
150-
'prefer-template': 'off',
151132
},
152133
},
153134
],

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
],
1414
"author": "IBM Corp.",
1515
"scripts": {
16-
"eslint:fix": "eslint . --ext .ts,.js --fix",
17-
"eslint:check": "eslint . --ext .ts,.js --cache",
16+
"eslint:fix": "eslint . --ext .ts,.js,.mjs --fix",
17+
"eslint:check": "eslint . --ext .ts,.js,.mjs --cache",
1818
"lint": "npm run eslint:check",
1919
"lint-fix": "npm run eslint:fix",
2020
"copymeta": "[ -d 'dist' ] && cp package.json LICENSE README.md dist/",

test/examples/src/features/js/startAndProcess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
import { ChangesFollower, CloudantV1 } from '../../../../../index';
17-
const { Writable } = require('node:stream');
18-
const { pipeline } = require('node:stream/promises');
17+
import { Writable } from 'node:stream';
18+
import { pipeline } from 'node:stream/promises';
1919

2020
const client = CloudantV1.newInstance();
2121
// Start from a previously persisted seq

test/examples/src/features/js/startOneOffAndProcess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
import { ChangesFollower, CloudantV1 } from '../../../../../index';
17-
const { Writable } = require('node:stream');
18-
const { pipeline } = require('node:stream/promises');
17+
import { Writable } from 'node:stream';
18+
import { pipeline } from 'node:stream/promises';
1919

2020
const client = CloudantV1.newInstance();
2121
// Start from a previously persisted seq

test/examples/src/features/js/stop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
import { ChangesFollower, CloudantV1 } from '../../../../../index';
17-
const { Writable } = require('node:stream');
18-
const { pipeline } = require('node:stream/promises');
17+
import { Writable } from 'node:stream';
18+
import { pipeline } from 'node:stream/promises';
1919

2020
const client = CloudantV1.newInstance();
2121
const changesParams = {

test/examples/src/js/CreateDbAndDoc.js renamed to test/examples/src/js/CreateDbAndDoc.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* eslint-disable no-console */
1818

19-
const { CloudantV1 } = require('../../../../index.ts');
19+
import { CloudantV1 } from '../../../../index';
2020

2121
// when you change this file, please run test/examples/src/js/CreateOutputs.js so that the output files are updated
2222

@@ -86,4 +86,4 @@ if (require.main === module) {
8686
createDbAndDoc();
8787
}
8888

89-
module.exports = { createDbAndDoc };
89+
export default { createDbAndDoc };

test/examples/src/js/CreateOutputs.js renamed to test/examples/src/js/CreateOutputs.mjs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
* Run this script from the root folder to regenerate outputs of example codes.
1919
*/
2020

21-
const fs = require('fs');
21+
import { writeFile } from 'node:fs';
2222

23-
const {
24-
getInfoFromExistingDatabase,
25-
} = require('./GetInfoFromExistingDatabase.js');
26-
const { createDbAndDoc } = require('./CreateDbAndDoc.js');
27-
const { updateDoc } = require('./UpdateDoc.js');
28-
const { deleteDoc } = require('./DeleteDoc.js');
23+
import { getInfoFromExistingDatabase } from './GetInfoFromExistingDatabase';
24+
import { createDbAndDoc } from './CreateDbAndDoc';
25+
import { updateDoc } from './UpdateDoc';
26+
import { deleteDoc } from './DeleteDoc';
2927

3028
let consoleOutput = ''; // flush consoleOutput
3129
const mockedLog = (output) => {
@@ -36,7 +34,7 @@ global.console.log = mockedLog; // Mock console.log
3634
const run = async () => {
3735
await createDbAndDoc();
3836

39-
fs.writeFile(
37+
writeFile(
4038
'test/examples/output/CreateDbAndDoc.txt',
4139
consoleOutput.trim(),
4240
(err) => {
@@ -48,7 +46,7 @@ const run = async () => {
4846

4947
await getInfoFromExistingDatabase();
5048

51-
fs.writeFile(
49+
writeFile(
5250
'test/examples/output/GetInfoFromExistingDatabase.txt',
5351
consoleOutput.trim(),
5452
(err) => {
@@ -60,7 +58,7 @@ const run = async () => {
6058

6159
await updateDoc();
6260

63-
fs.writeFile(
61+
writeFile(
6462
'test/examples/output/UpdateDoc.txt',
6563
consoleOutput.trim(),
6664
(err) => {
@@ -72,7 +70,7 @@ const run = async () => {
7270

7371
await deleteDoc();
7472

75-
fs.writeFile(
73+
writeFile(
7674
'test/examples/output/DeleteDoc.txt',
7775
consoleOutput.trim(),
7876
(err) => {

test/examples/src/js/DeleteDoc.js renamed to test/examples/src/js/DeleteDoc.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* eslint-disable no-console */
1818

19-
const { CloudantV1 } = require('../../../../index.ts');
19+
import { CloudantV1 } from '../../../../index';
2020

2121
// when you change this file, please run test/examples/src/js/CreateOutputs.js so that the output files are updated
2222

@@ -58,4 +58,4 @@ if (require.main === module) {
5858
deleteDoc();
5959
}
6060

61-
module.exports = { deleteDoc };
61+
export default { deleteDoc };

test/examples/src/js/GetInfoFromExistingDatabase.js renamed to test/examples/src/js/GetInfoFromExistingDatabase.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* eslint-disable no-console */
1818

19-
const { CloudantV1 } = require('../../../../index.ts');
19+
import { CloudantV1 } from '../../../../index';
2020

2121
// when you change this file, please run test/examples/src/js/CreateOutputs.js so that the output files are updated
2222

@@ -60,4 +60,4 @@ if (require.main === module) {
6060
getInfoFromExistingDatabase();
6161
}
6262

63-
module.exports = { getInfoFromExistingDatabase };
63+
export default { getInfoFromExistingDatabase };

test/examples/src/js/UpdateDoc.js renamed to test/examples/src/js/UpdateDoc.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* eslint-disable no-console */
1818

19-
const { CloudantV1 } = require('../../../../index.ts');
19+
import { CloudantV1 } from '../../../../index';
2020

2121
// when you change this file, please run test/examples/src/js/CreateOutputs.js so that the output files are updated
2222

@@ -108,4 +108,4 @@ if (require.main === module) {
108108
updateDoc();
109109
}
110110

111-
module.exports = { updateDoc };
111+
export default { updateDoc };

0 commit comments

Comments
 (0)