mirror of
https://github.com/samuele-cozzi/obsidian-marp-slides.git
synced 2026-07-22 07:40:25 +00:00
first unit test
This commit is contained in:
parent
81274b9d91
commit
886d72f0ff
8 changed files with 2961 additions and 68 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -20,3 +20,5 @@ data.json
|
||||||
|
|
||||||
# Exclude macOS Finder (System Explorer) View States
|
# Exclude macOS Finder (System Explorer) View States
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
tests/coverage
|
||||||
|
|
|
||||||
14
jest.config.js
Normal file
14
jest.config.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
//modulePathIgnorePatterns: ["<rootDir>/docs/","<rootDir>/vault/"],
|
||||||
|
|
||||||
|
coverageDirectory: "tests/coverage",
|
||||||
|
coverageReporters: ["lcov"],
|
||||||
|
|
||||||
|
modulePaths: ['node_modules','<rootDir>'],
|
||||||
|
moduleDirectories: ['node_modules'],
|
||||||
|
moduleFileExtensions: ['js', 'mjs', 'cjs', 'jsx', 'ts', 'd.ts', 'tsx', 'json', 'node']
|
||||||
|
|
||||||
|
};
|
||||||
2830
package-lock.json
generated
2830
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,20 +6,26 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node esbuild.config.mjs",
|
"dev": "node esbuild.config.mjs",
|
||||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||||
|
"test": "jest --coverage --silent=false",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^29.4.0",
|
||||||
"@types/node": "^16.11.6",
|
"@types/node": "^16.11.6",
|
||||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||||
"@typescript-eslint/parser": "5.29.0",
|
"@typescript-eslint/parser": "5.29.0",
|
||||||
"builtin-modules": "3.3.0",
|
"builtin-modules": "3.3.0",
|
||||||
"esbuild": "0.17.3",
|
"esbuild": "0.17.3",
|
||||||
|
"jest": "^29.5.0",
|
||||||
|
"normalize-path": "^3.0.0",
|
||||||
"obsidian": "latest",
|
"obsidian": "latest",
|
||||||
|
"ts-jest": "^29.0.5",
|
||||||
"tslib": "2.4.0",
|
"tslib": "2.4.0",
|
||||||
"typescript": "4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@marp-team/marp-cli": "^2.4.0",
|
"@marp-team/marp-cli": "^2.4.0",
|
||||||
|
|
|
||||||
46
src/main.ts
46
src/main.ts
|
|
@ -1,9 +1,9 @@
|
||||||
import { MarkdownView, TAbstractFile, Plugin, addIcon } from 'obsidian';
|
import { MarkdownView, TAbstractFile, Plugin, addIcon, App, PluginSettingTab, Setting } from 'obsidian';
|
||||||
|
|
||||||
import { MARP_PREVIEW_VIEW, MarpPreviewView } from './views/marpPreviewView';
|
import { MARP_PREVIEW_VIEW, MarpPreviewView } from './views/marpPreviewView';
|
||||||
import { MarpExport } from './utilities/marpExport';
|
import { MarpExport } from './utilities/marpExport';
|
||||||
import { ICON_SLIDE_PREVIEW } from './utilities/icons';
|
import { ICON_SLIDE_PREVIEW } from './utilities/icons';
|
||||||
import { MarpSlidesSettings, MarpSlidesSettingTab, DEFAULT_SETTINGS } from 'utilities/settings';
|
import { MarpSlidesSettings, DEFAULT_SETTINGS } from 'utilities/settings';
|
||||||
|
|
||||||
|
|
||||||
export default class MarpSlides extends Plugin {
|
export default class MarpSlides extends Plugin {
|
||||||
|
|
@ -148,3 +148,45 @@ export default class MarpSlides extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class MarpSlidesSettingTab extends PluginSettingTab {
|
||||||
|
private plugin: MarpSlides;
|
||||||
|
|
||||||
|
constructor(app: App, plugin: MarpSlides) {
|
||||||
|
super(app, plugin);
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
display(): void {
|
||||||
|
const {containerEl} = this;
|
||||||
|
|
||||||
|
containerEl.empty();
|
||||||
|
|
||||||
|
containerEl.createEl('h2', {text: 'MARP Slide Plugin - Settings'});
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Chrome Path')
|
||||||
|
.setDesc('Sets the custom path for Chrome or Chromium-based browser to export PDF, PPTX, and image. If it\'s empty, Marp will find out the installed Google Chrome / Chromium / Microsoft Edge.')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('Enter CHROME_PATH')
|
||||||
|
.setValue(this.plugin.settings.CHROME_PATH)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
console.log('Chrome Path: ' + value);
|
||||||
|
this.plugin.settings.CHROME_PATH = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Theme Path')
|
||||||
|
.setDesc('Local paths to additional <a href="https://marpit.marp.app/theme-css">theme CSS</a> for Marp core and Marpit framework. The rule for paths is following Markdown: Styles.')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('template\\marp\\themes')
|
||||||
|
.setValue(this.plugin.settings.ThemePath)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
console.log('Theme Path: ' + value);
|
||||||
|
this.plugin.settings.ThemePath = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
import { App, PluginSettingTab, Setting } from 'obsidian';
|
|
||||||
import MarpSlides from '../main';
|
|
||||||
|
|
||||||
export interface MarpSlidesSettings {
|
export interface MarpSlidesSettings {
|
||||||
CHROME_PATH: string;
|
CHROME_PATH: string;
|
||||||
ThemePath: string;
|
ThemePath: string;
|
||||||
|
|
@ -9,46 +6,4 @@ export interface MarpSlidesSettings {
|
||||||
export const DEFAULT_SETTINGS: MarpSlidesSettings = {
|
export const DEFAULT_SETTINGS: MarpSlidesSettings = {
|
||||||
CHROME_PATH: '',
|
CHROME_PATH: '',
|
||||||
ThemePath: ''
|
ThemePath: ''
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class MarpSlidesSettingTab extends PluginSettingTab {
|
|
||||||
private plugin: MarpSlides;
|
|
||||||
|
|
||||||
constructor(app: App, plugin: MarpSlides) {
|
|
||||||
super(app, plugin);
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
display(): void {
|
|
||||||
const {containerEl} = this;
|
|
||||||
|
|
||||||
containerEl.empty();
|
|
||||||
|
|
||||||
containerEl.createEl('h2', {text: 'MARP Slide Plugin - Settings'});
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Chrome Path')
|
|
||||||
.setDesc('Sets the custom path for Chrome or Chromium-based browser to export PDF, PPTX, and image. If it\'s empty, Marp will find out the installed Google Chrome / Chromium / Microsoft Edge.')
|
|
||||||
.addText(text => text
|
|
||||||
.setPlaceholder('Enter CHROME_PATH')
|
|
||||||
.setValue(this.plugin.settings.CHROME_PATH)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
console.log('Chrome Path: ' + value);
|
|
||||||
this.plugin.settings.CHROME_PATH = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
}));
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Theme Path')
|
|
||||||
.setDesc('Local paths to additional <a href="https://marpit.marp.app/theme-css">theme CSS</a> for Marp core and Marpit framework. The rule for paths is following Markdown: Styles.')
|
|
||||||
.addText(text => text
|
|
||||||
.setPlaceholder('template\\marp\\themes')
|
|
||||||
.setValue(this.plugin.settings.ThemePath)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
console.log('Theme Path: ' + value);
|
|
||||||
this.plugin.settings.ThemePath = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
32
tests/__mocks__/obsidian.ts
Normal file
32
tests/__mocks__/obsidian.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
const normalize = require('normalize-path');
|
||||||
|
|
||||||
|
// Import this named export into your test file:
|
||||||
|
export const TFile = jest.fn().mockImplementation(() => {
|
||||||
|
return {
|
||||||
|
constructor: () => {},
|
||||||
|
path: String,
|
||||||
|
parent: () => new TFile,
|
||||||
|
vault: new Vault()
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export const Vault = jest.fn().mockImplementation(() => {
|
||||||
|
return {
|
||||||
|
constructor: () => {},
|
||||||
|
adapter: new FileSystemAdapter
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FileSystemAdapter = jest.fn().mockImplementation(() => {
|
||||||
|
let _path : string = ""
|
||||||
|
return {
|
||||||
|
constructor: () => {},
|
||||||
|
write: (path: string, data: string) => { _path = path},
|
||||||
|
getBasePath: () => { return _path; }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export const normalizePath = jest.fn().mockImplementation((str: string) => {
|
||||||
|
return normalize(str)
|
||||||
|
})
|
||||||
52
tests/filePath.test.ts
Normal file
52
tests/filePath.test.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { TFile } from 'obsidian';
|
||||||
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
import { FilePath } from "../src/utilities/filePath";
|
||||||
|
import { DEFAULT_SETTINGS } from "../src/utilities/settings";
|
||||||
|
|
||||||
|
class pathsUtility {
|
||||||
|
base: string;
|
||||||
|
relative: string;
|
||||||
|
expected:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('file base path', () => {
|
||||||
|
|
||||||
|
const filePath = new FilePath(DEFAULT_SETTINGS);
|
||||||
|
const tests : pathsUtility[] = [
|
||||||
|
{ base: "aaa", relative: "bbb", expected: "aaa/bbb/"}//,
|
||||||
|
//{ base: "C:\\user\\foo\\vault", relative: "\\folder\\file", expected: "C:\\user\\foo\\vault\\folder\\file\\"},
|
||||||
|
];
|
||||||
|
|
||||||
|
tests.forEach(element => {
|
||||||
|
const file = new TFile;
|
||||||
|
|
||||||
|
file.parent.path = element.relative;
|
||||||
|
file.vault.adapter.write(element.base, '');
|
||||||
|
|
||||||
|
const result = filePath.getCompleteFileBasePath(file);
|
||||||
|
|
||||||
|
expect(result).toBe(element.expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// test('file path', () => {
|
||||||
|
|
||||||
|
// const filePath = new FilePath(DEFAULT_SETTINGS);
|
||||||
|
// const tests : pathsUtility[] = [
|
||||||
|
// { base: "aaa", relative: "bbb.md", expected: "aaa/bbb.md"},
|
||||||
|
// { base: "C:\\user\\foo\\vault", relative: "\\folder\\file.md", expected: "C:\\user\\foo\\vault\\folder\\file.md"},
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// tests.forEach(element => {
|
||||||
|
// const file = new TFile;
|
||||||
|
|
||||||
|
// file.parent.path = element.relative;
|
||||||
|
// file.vault.adapter.write(element.base, '');
|
||||||
|
|
||||||
|
// const result = filePath.getCompleteFilePath(file);
|
||||||
|
|
||||||
|
// expect(result).toBe(element.expected);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// });
|
||||||
Loading…
Reference in a new issue