Skip to content

Commit

Permalink
Merge pull request #8 from fastai/add-tests
Browse files Browse the repository at this point in the history
update data for test files
  • Loading branch information
hamelsmu authored Mar 31, 2023
2 parents 808ab3a + 6d20885 commit 53f3207
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"${workspaceFolder}/out/**/*.js",
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "tasks: watch-tests"
"preLaunchTask": "${defaultBuildTask}"
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"dist": true // set this to false to include "dist" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"terminal.integrated.inheritEnv": true,
}
4 changes: 3 additions & 1 deletion src/test/data/testproject1/nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@
},
"outputs": [],
"source": [
"Hello somerthing else"
"#|hide\n",
"#|eval: false\n",
"pass"
]
},
{
Expand Down
34 changes: 26 additions & 8 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import path = require('path');
import * as vscode from 'vscode';
import { getDirectives } from "../../utils/nb";

// const content = fs.readFileSync(nbPath, 'utf8');
// const notebookJson = JSON.parse(content);


suite('Extension Test Suite', () => {
const testProjectPath = path.join(__dirname, "data", "testproject1");
const nbPath = path.join(testProjectPath, "nbs", "00_core.ipynb");

const content = fs.readFileSync(nbPath, 'utf8');
const notebookJson = JSON.parse(content);
const codeCells = notebookJson.cells.filter((x: any) => x.cell_type === 'code');
codeCells.getCode = function(index:number) {
return this[index].source.join('');
};

vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
Expand All @@ -23,8 +27,22 @@ suite('Extension Test Suite', () => {
});

test('nb.getDirectives', () => {
const content = fs.readFileSync(nbPath, 'utf8');
console.log(content)
assert.strictEqual(-1, -1);

function checkDirective(cellNum: number, expected: string){
//check if the cell has the directive
const directives = getDirectives(codeCells.getCode(cellNum));
// @ts-ignore
assert.ok(expected in directives);
}

// this cell has an export directive
checkDirective(1, 'export');

// this cell has an eval directive
checkDirective(3, 'eval');

// this cell has a hide and eval directive
checkDirective(8, 'hide');
checkDirective(8, 'eval');
});
});
});

0 comments on commit 53f3207

Please sign in to comment.