|
| 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