(core) bump mocha version to allow parallel tests; move more tests to core

Summary:
This uses a newer version of mocha in grist-core so that tests can be run in parallel. That allows more tests to be moved without slowing things down overall. Tests moved are venerable browser tests; only the ones that "just work" or worked without too much trouble to are moved, in order to keep the diff from growing too large. Will wrestle with more in follow up.

Parallelism is at the file level, rather than the individual test.

The newer version of mocha isn't needed for grist-saas repo; tests are parallelized in our internal CI by other means. I've chosen to allocate files to workers in a cruder way than our internal CI, based on initial characters rather than an automated process. The automated process would need some reworking to be compatible with mocha running in parallel mode.

Test Plan: this diff was tested first on grist-core, then ported to grist-saas so saas repo history will correctly track history of moved files.

Reviewers: jarek

Reviewed By: jarek

Subscribers: jarek

Differential Revision: https://phab.getgrist.com/D3927
This commit is contained in:
Paul Fitzpatrick
2023-06-27 02:11:08 -04:00
parent 7d3b4b49d5
commit bcbf57d590
126 changed files with 6833 additions and 759 deletions

View File

@@ -0,0 +1,34 @@
const grist = require('grist-plugin-api');
const {foo} = grist.rpc.getStub('foo@grist');
let tableId = 'Table1';
const colId = 'A';
let promise = Promise.resolve(true);
grist.rpc.on('message', msg => {
if (msg.type === "docAction") {
if (msg.action[0] === 'RenameTable') {
tableId = msg.action[2];
}
promise = getColValues(colId).then(foo);
}
});
function getColValues(colId) {
return grist.docApi.fetchTable(tableId).then(data => data[colId]);
}
class TestSubscribe {
invoke(api, name, args){
return grist[api][name](...args);
}
// Returns a promise that resolves when an ongoing call resolves. Resolves right-awa if plugin has
// no pending call.
waitForPlugin() {
return promise.then(() => true);
}
}
module.exports = TestSubscribe;

View File

@@ -0,0 +1,21 @@
const grist = require('grist-plugin-api');
const TestSubscribe = require('./TestSubscribe');
grist.rpc.registerImpl("testApiNode", { // todo rename to testGristDocApiNode
invoke: (name, args) => {
const api = grist.rpc.getStub("GristDocAPI@grist", grist.checkers.GristDocAPI);
return api[name](...args)
.then((result) => [`node-GristDocAPI ${name}(${args.join(",")})`, result]);
},
});
grist.rpc.registerImpl("testDocStorage", {
invoke: (name, args) => {
const api = grist.rpc.getStub("DocStorage@grist", grist.checkers.Storage);
return api[name](...args);
},
});
grist.rpc.registerImpl("testSubscribe", new TestSubscribe());
grist.ready();

View File

@@ -0,0 +1,7 @@
name: node-GristDocAPI
version: 0.0.0
description:
components:
unsafeNode: main.js
contributions: {}

View File

@@ -0,0 +1,3 @@
// die immediately.

View File

@@ -0,0 +1,11 @@
name: node-fail
version: 0.0.0
description:
components:
unsafeNode: main.js
contributions:
fileParsers:
- fileExtensions: ["csv"]
parseFile:
component: unsafeNode
name: node-fail

View File

@@ -0,0 +1,11 @@
name: minicsv
version: 0.0.0
description: minicsv
components:
unsafeNode: nodebox/main.js
contributions:
fileParsers:
- fileExtensions: ["csv"]
parseFile:
component: unsafeNode
name: MiniCSV

View File

@@ -0,0 +1,69 @@
/**
*
* A minimal CSV reader with no type detection.
* All communication done by hand - real plugins should have helper code for
* RPC.
*
*/
const csv = require('csv');
const fs = require('fs');
const path = require('path');
function readCsv(data, replier) {
csv.parse(data, {}, function(err, output) {
const result = {
parseOptions: {
options: ""
},
tables: [
{
table_name: "space-monkey" + require('dependency_test'),
column_metadata: output[0].map(name => {
return {
id: name,
type: 'Text'
};
}),
table_data: output[0].map((name, idx) => {
return output.slice(1).map(row => row[idx]);
})
}
]
};
replier(result);
});
}
function processMessage(msg, replier, error_replier) {
if (msg.meth == 'parseFile') {
var dir = msg.dir;
var fname = msg.args[0].path;
var data = fs.readFileSync(path.resolve(dir, fname));
readCsv(data, replier);
} else {
error_replier('unknown method');
}
}
process.on('message', (m) => {
const sendReply = (result) => {
process.send({
mtype: 2, /* RespData */
reqId: m.reqId,
data: result
});
};
const sendError = (txt) => {
process.send({
mtype: 3, /* RespErr */
reqId: m.reqId,
mesg: txt
});
};
processMessage(m, sendReply, sendError);
});
// Once we have a handler for 'message' set up, send home a ready
// message to give the all-clear.
process.send({ mtype: 4, data: {ready: true }});

View File

@@ -0,0 +1,3 @@
"use strict";
module.exports = 42;

View File

@@ -0,0 +1,11 @@
{
"name": "dependency_test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

View File

@@ -0,0 +1,3 @@
process.send({ greeny: true });

View File

@@ -0,0 +1,11 @@
name: node-wrong-message
version: 0.0.0
description:
components:
unsafeNode: main.js
contributions:
fileParsers:
- fileExtensions: ["csv"]
parseFile:
component: unsafeNode
name: node-wrong-message

View File

@@ -0,0 +1,10 @@
name: validPluginName
version: 0.0.1
components:
safeBrowser: '.'
contributions:
importSources:
- importSource:
component: "safeBrowser"
name: index.html
label: My custom safe importer