Skip to content

Commit

Permalink
added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrik committed Aug 29, 2022
1 parent 14a240c commit 8576cf1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/NotebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
});
}

_.last(commentCells).metadata.trailing = content.substring(previouseEnd, end);
if (commentCells.length) {
_.last(commentCells).metadata.trailing = content.substring(previouseEnd, end);
}

return commentCells;
}
Expand Down
59 changes: 59 additions & 0 deletions src/extension-test/integration/suite/serialization-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import assert = require('assert');
import * as fsPromises from 'fs/promises';
import path = require('path');
import * as testUtil from './util';
import { NotebookProvider } from '../../../NotebookProvider';
import { before, after } from 'mocha';
import { serialize } from 'v8';
import _ = require('lodash');

const tester = new NotebookProvider();
const suiteName = 'notebook';
const decoder = new TextDecoder();

const ignoreList = ['highlight_test.clj'];

async function absoluteFileNamesIn(directoryName, results: string[] = []) {
const files = await fsPromises.readdir(directoryName, { withFileTypes: true });
for (const f of files) {
const fullPath = path.join(directoryName, f.name);
if (f.isDirectory()) {
await absoluteFileNamesIn(fullPath, results);
} else {
results.push(fullPath);
}
}
return results;
}

suite('serialization', () => {
before(() => {
testUtil.showMessage(suiteName, `suite starting!`);
});

after(() => {
testUtil.showMessage(suiteName, `suite done!`);
});

test('input equals output', async () => {
const testFilePath = path.join(testUtil.testDataDir, '..');

const fileNames = await absoluteFileNamesIn(testFilePath);

const contents = await Promise.all(
fileNames
.filter(
(x) =>
'.clj' === path.parse(x).ext && _.some(ignoreList, (toIgnore) => !x.endsWith(toIgnore))
)
.map((name) => fsPromises.readFile(name))
);

for (const fileBuffer of contents) {
const notebook = await tester.deserializeNotebook(fileBuffer, null);
const serializedNotebook = await tester.serializeNotebook(notebook, null);

assert.equal(decoder.decode(serializedNotebook), decoder.decode(fileBuffer));
}
});
});

0 comments on commit 8576cf1

Please sign in to comment.