diff --git a/.vscode/launch.json b/.vscode/launch.json index d4df9e9..b2cfe23 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -29,7 +29,7 @@ "${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js" ], - "preLaunchTask": "tasks: watch-tests" + "preLaunchTask": "${defaultBuildTask}" } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c5ac48..7745f0c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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, } \ No newline at end of file diff --git a/src/test/data/testproject1/nbs/00_core.ipynb b/src/test/data/testproject1/nbs/00_core.ipynb index 9318d9b..d25405a 100644 --- a/src/test/data/testproject1/nbs/00_core.ipynb +++ b/src/test/data/testproject1/nbs/00_core.ipynb @@ -168,7 +168,9 @@ }, "outputs": [], "source": [ - "Hello somerthing else" + "#|hide\n", + "#|eval: false\n", + "pass" ] }, { diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 4a60a83..8c9d49e 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -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', () => { @@ -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'); }); -}); \ No newline at end of file +});