Skip to content

Commit f1deedd

Browse files
committed
added integration tests
1 parent fb35441 commit f1deedd

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/NotebookProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
9292
});
9393
}
9494

95-
_.last(commentCells).metadata.trailing = content.substring(previouseEnd, end);
95+
if (commentCells.length) {
96+
_.last(commentCells).metadata.trailing = content.substring(previouseEnd, end);
97+
}
9698

9799
return commentCells;
98100
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import assert = require('assert');
2+
import * as fsPromises from 'fs/promises';
3+
import path = require('path');
4+
import * as testUtil from './util';
5+
import { NotebookProvider } from '../../../NotebookProvider';
6+
import { before, after } from 'mocha';
7+
import { serialize } from 'v8';
8+
import _ = require('lodash');
9+
10+
const tester = new NotebookProvider();
11+
const suiteName = 'notebook';
12+
const decoder = new TextDecoder();
13+
14+
const ignoreList = ['highlight_test.clj'];
15+
16+
async function absoluteFileNamesIn(directoryName, results: string[] = []) {
17+
const files = await fsPromises.readdir(directoryName, { withFileTypes: true });
18+
for (const f of files) {
19+
const fullPath = path.join(directoryName, f.name);
20+
if (f.isDirectory()) {
21+
await absoluteFileNamesIn(fullPath, results);
22+
} else {
23+
results.push(fullPath);
24+
}
25+
}
26+
return results;
27+
}
28+
29+
suite('serialization', () => {
30+
before(() => {
31+
testUtil.showMessage(suiteName, `suite starting!`);
32+
});
33+
34+
after(() => {
35+
testUtil.showMessage(suiteName, `suite done!`);
36+
});
37+
38+
test('input equals output', async () => {
39+
const testFilePath = path.join(testUtil.testDataDir, '..');
40+
41+
const fileNames = await absoluteFileNamesIn(testFilePath);
42+
43+
const contents = await Promise.all(
44+
fileNames
45+
.filter(
46+
(x) =>
47+
'.clj' === path.parse(x).ext && _.some(ignoreList, (toIgnore) => !x.endsWith(toIgnore))
48+
)
49+
.map((name) => fsPromises.readFile(name))
50+
);
51+
52+
for (const fileBuffer of contents) {
53+
const notebook = await tester.deserializeNotebook(fileBuffer, null);
54+
const serializedNotebook = await tester.serializeNotebook(notebook, null);
55+
56+
assert.equal(decoder.decode(serializedNotebook), decoder.decode(fileBuffer));
57+
}
58+
});
59+
});

0 commit comments

Comments
 (0)