-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/extension-test/integration/suite/serialization-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
}); | ||
}); |