(core) Remove transform columns on shutdown

Summary: Call a new user action `RemoveTransformColumns` in ActiveDoc shutdown.

Test Plan: Added nbrowser test

Reviewers: georgegevoian, paulfitz

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4107
This commit is contained in:
Alex Hall
2023-11-13 22:59:23 +02:00
parent 3dfe4be5f3
commit 5197891427
7 changed files with 84 additions and 22 deletions

Binary file not shown.

View File

@@ -0,0 +1,35 @@
import {assert, driver} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {server, setupTestSuite} from "test/nbrowser/testUtils";
describe('RemoveTransformColumns', function () {
this.timeout(4000);
setupTestSuite();
it('should remove transform columns when the doc shuts down', async function () {
await server.simulateLogin("Chimpy", "chimpy@getgrist.com", 'nasa');
const doc = await gu.importFixturesDoc('chimpy', 'nasa', 'Horizon', 'RemoveTransformColumns.grist', false);
await driver.get(`${server.getHost()}/o/nasa/doc/${doc.id}`);
await gu.waitForDocToLoad();
assert.deepEqual(await gu.getVisibleGridCells({col: 'B', rowNums: [1]}), [
'manualSort, A, B, C, ' +
'gristHelper_Converted, gristHelper_Transform, ' +
'gristHelper_Converted2, gristHelper_Transform2'
]);
const userAPI = gu.createHomeApi('chimpy', 'nasa');
await userAPI.applyUserActions(doc.id, [["Calculate"]]); // finish loading fully
await userAPI.getDocAPI(doc.id).forceReload();
await driver.get(`${server.getHost()}/o/nasa/doc/${doc.id}`);
await gu.waitForDocToLoad();
assert.deepEqual(await gu.getVisibleGridCells({col: 'B', rowNums: [1]}), [
'manualSort, A, B, C'
]);
await gu.checkForErrors();
});
});

View File

@@ -67,7 +67,7 @@ class CaptureTransport extends winston.Transport {
private _captureFunc: (level: string, msg: string, meta: any) => void;
public constructor(options: any) {
super();
super(options);
this._captureFunc = options.captureFunc;
if (options.name) {
this.name = options.name;
@@ -125,7 +125,8 @@ export function setTmpLogLevel(level: string, optCaptureFunc?: (level: string, m
* strings. These may be tested using testUtils.assertMatchArray(). Callback may return a promise.
*/
export async function captureLog(
minLevel: string, callback: (messages: string[]) => void|Promise<void>
minLevel: string, callback: (messages: string[]) => void|Promise<void>,
options: {timestamp: boolean} = {timestamp: false}
): Promise<string[]> {
const messages: string[] = [];
const prevLogLevel = log.transports.file.level;
@@ -133,14 +134,15 @@ export async function captureLog(
function capture(level: string, msg: string, meta: any) {
if ((log as any).levels[level] <= (log as any).levels[minLevel]) { // winston types are off?
messages.push(level + ': ' + msg + (meta ? ' ' + serialize(meta) : ''));
const timePrefix = options.timestamp ? new Date().toISOString() + ' ' : '';
messages.push(`${timePrefix}${level}: ${msg}${meta ? ' ' + serialize(meta) : ''}`);
}
}
if (!process.env.VERBOSE) {
log.transports.file.level = -1 as any; // Suppress all log output.
}
log.add(CaptureTransport as any, { captureFunc: capture, name }); // types are off.
log.add(CaptureTransport as any, { captureFunc: capture, name, level: minLevel}); // types are off.
try {
await callback(messages);
} finally {