Skip to content

Commit 88c509d

Browse files
committed
MLE-21557 : Node Client Api mjs tests are failing for 12-nightly due to changes in the server code.
1 parent 369ee68 commit 88c509d

File tree

4 files changed

+69
-9
lines changed

4 files changed

+69
-9
lines changed

gulpfile.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const proxy = require('./lib/proxy-generator.js');
2626
const testproxy = require('./test-basic-proxy/testGenerator.js');
2727
const testconfig = require('./etc/test-config.js');
2828
const basicloader = require('./lib/basic-loader.js');
29+
const streamToArray = require("stream-to-array");
2930

3031
function lint() {
3132
return gulp.src('lib/*')
@@ -90,6 +91,48 @@ function loadProxyTestInspector(callback) {
9091
});
9192
}
9293

94+
function updateMjsFiles(callback){
95+
const testlib = require("./etc/test-lib");
96+
let serverConfiguration = {};
97+
testlib.findServerConfigurationPromise(serverConfiguration)
98+
.then(() => {
99+
if(serverConfiguration.serverVersion<12){
100+
callback();
101+
} else {
102+
const query = marklogic.queryBuilder.where(
103+
marklogic.ctsQueryBuilder.cts.directoryQuery('/dbf/test/', 'infinity'));
104+
streamToArray(getTestModulesClient().documents.queryAll(query),
105+
function(err, arr ) {
106+
if(err){
107+
throw new Error(err);
108+
}
109+
arr.forEach(uri=> {
110+
if(uri && uri.toString().endsWith(".mjs")){
111+
getTestModulesClient().documents.read(uri.toString())
112+
.result(function(documents){
113+
const lines = documents[0].content.split('\n');
114+
let i=lines.length-1;
115+
while(lines[i]===""){
116+
i--;
117+
}
118+
lines[i] = 'export default ' + lines[i];
119+
getTestModulesClient().documents.write({
120+
uri: uri.toString(),
121+
content: lines.join('\n')
122+
})
123+
.result(function(response){callback();})
124+
})
125+
126+
} else {
127+
callback();
128+
}
129+
});
130+
131+
});
132+
}
133+
}).catch((error) => {throw new Error(error);});
134+
}
135+
93136
function loadProxyTestData(callback) {
94137
const testdir = path.resolve('test-basic-proxy');
95138
const filePath = path.resolve(testdir, 'testdef.json');
@@ -158,11 +201,11 @@ exports.loadProxyTests = parallel(loadProxyTestInspector, loadProxyTestData,
158201
exports.generateProxyTests = parallel(positiveProxyTests, negativeProxyTests, generatedProxyTests);
159202
exports.runProxyTests = runProxyTests;
160203
exports.setupProxyTests = series(
161-
parallel(loadProxyTestInspector, loadProxyTestData, loadProxyTestCases),
162-
parallel(positiveProxyTests, negativeProxyTests, generatedProxyTests));
204+
parallel(loadProxyTestInspector, loadProxyTestData, loadProxyTestCases,),
205+
parallel(positiveProxyTests, negativeProxyTests, generatedProxyTests), updateMjsFiles);
163206
exports.proxyTests = series(
164207
parallel(loadProxyTestInspector, loadProxyTestData, loadProxyTestCases),
165-
parallel(positiveProxyTests, negativeProxyTests, generatedProxyTests),
208+
parallel(positiveProxyTests, negativeProxyTests, generatedProxyTests), updateMjsFiles,
166209
runProxyTests);
167210
exports.test = test;
168211
exports.default = lint;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const result = {
2+
"hello": "world",
3+
"yourParam": external.myParam,
4+
"theDoc": external.doc
5+
}
6+
export default result
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const result = {"hello": "world",
2+
"Patch1": external.patch1,
3+
"Patch2": external.patch2,
4+
"theDoc": external.doc}
5+
export default result

test-basic/transformDoc-test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const testlib = require("../etc/test-lib");
2323
const op = marklogic.planBuilder;
2424
let removeStream = new Stream.PassThrough({objectMode: true});
2525
let serverConfiguration = {};
26+
let transformDoc;
27+
let transformDocWithTwoParams;
2628

2729
describe('optic-update transformDoc tests', function() {
2830
this.timeout(6000);
@@ -40,6 +42,10 @@ describe('optic-update transformDoc tests', function() {
4042
if(serverConfiguration.serverVersion < 11){
4143
this.skip();
4244
}
45+
transformDoc = serverConfiguration.serverVersion < 12?'/optic/test/transformDoc-test.mjs':
46+
'/optic/test/transformDoc-test-forServerVersion12.mjs';
47+
transformDocWithTwoParams = serverConfiguration.serverVersion < 12?'/optic/test/transformDoc-test-two-params.mjs':
48+
'/optic/test/transformDoc-test-two-params-forServerVersion12.mjs';
4349
let readable = new Stream.Readable({objectMode: true});
4450
removeStream = new Stream.PassThrough({objectMode: true});
4551
const musician = {
@@ -78,7 +84,7 @@ describe('optic-update transformDoc tests', function() {
7884
try {
7985
const plan = op.fromDocUris('/test/optic/transformDoc/data1.json')
8086
.joinDoc(op.col("doc"), op.col("uri"))
81-
.transformDoc('doc', {"path": "/optic/test/transformDoc-test.mjs"})
87+
.transformDoc('doc', {"path": transformDoc})
8288
.orderBy(op.col('uri'));
8389

8490
db.rows.query(plan).then(res => {
@@ -96,7 +102,7 @@ describe('optic-update transformDoc tests', function() {
96102
try {
97103
const plan = op.fromDocUris('/test/optic/transformDoc/data1.json')
98104
.joinDoc(op.col("doc"), op.col("uri"))
99-
.transformDoc('doc', {"path": "/optic/test/transformDoc-test.mjs", kind: "mjs"})
105+
.transformDoc('doc', {"path": transformDoc, kind: "mjs"})
100106
.orderBy(op.col('uri'));
101107

102108
db.rows.query(plan).then(res => {
@@ -115,7 +121,7 @@ describe('optic-update transformDoc tests', function() {
115121
const plan = op.fromDocUris('/test/optic/transformDoc/data1.json')
116122
.joinDoc(op.col("doc"), op.col("uri"))
117123
.transformDoc('doc', {
118-
"path": "/optic/test/transformDoc-test.mjs",
124+
"path": transformDoc,
119125
kind: "mjs",
120126
params: {myParam: 'my new content'}
121127
})
@@ -141,7 +147,7 @@ describe('optic-update transformDoc tests', function() {
141147
const plan = op.fromDocUris('/test/optic/transformDoc/data1.json')
142148
.joinDoc(op.col("doc"), op.col("uri"))
143149
.transformDoc('doc', {
144-
"path": "/optic/test/transformDoc-test.mjs",
150+
"path": transformDoc,
145151
kind: "mjs",
146152
params: {wrongParamName: 'my new content'}
147153
})
@@ -188,7 +194,7 @@ describe('optic-update transformDoc tests', function() {
188194
];
189195
const plan = op.fromDocDescriptors(docsDescriptor)
190196
.transformDoc('doc', {
191-
"path": "/optic/test/transformDoc-test.mjs",
197+
"path": transformDoc,
192198
kind: "mjs",
193199
params: {myParam: 'my new content'}
194200
})
@@ -296,7 +302,7 @@ describe('optic-update transformDoc tests', function() {
296302
.joinInner(fromLiteral)
297303
.orderBy('id')
298304
.transformDoc('doc', {
299-
"path": "/optic/test/transformDoc-test-two-params.mjs", kind: "mjs",
305+
"path": transformDocWithTwoParams, kind: "mjs",
300306
params: {patch1: op.col('id'), patch2: op.col('val')}
301307
})
302308
.write({uri: 'uri', doc: 'doc'});

0 commit comments

Comments
 (0)