Finally got testing working!

This commit is contained in:
marley 2023-05-15 13:39:30 -07:00
parent 2a97cb358f
commit 87b631efff
9 changed files with 4205 additions and 74 deletions

1
.idea/ed-safari.iml Executable file → Normal file
View file

@ -8,5 +8,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="@types/mocha" level="application" />
</component>
</module>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$/test" libraries="{@types/mocha}" />
<excludedPredefinedLibrary name="HTML" />
</component>
</project>

6
babel.config.js Normal file
View file

@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};

10
jest.config.js Normal file
View file

@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
testEnvironment: 'node',
"transformIgnorePatterns": [
"/node_modules/(?!lodash-es/.*)"
],
transform: {
'\\.[tj]sx?$': ['babel-jest', { rootMode: 'upward' }],
}
};

4095
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,8 @@
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
"lint": "echo \"No linting configured\"",
"test": "jest"
},
"keywords": [],
"author": {
@ -22,6 +23,9 @@
"node 18"
],
"devDependencies": {
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@electron-forge/cli": "^6.1.1",
"@electron-forge/maker-deb": "^6.1.1",
"@electron-forge/maker-rpm": "^6.1.1",
@ -30,12 +34,15 @@
"@electron-forge/plugin-vite": "^6.1.1",
"@tsconfig/node-lts": "^18.12.2",
"@tsconfig/node20": "^1.0.0",
"@types/jest": "^29.5.1",
"@types/lodash-es": "^4.17.7",
"@types/node": "^20.1.2",
"@types/tail": "^2.2.1",
"autoprefixer": "^10.4.14",
"babel-jest": "^29.5.0",
"browserslist": "^4.21.5",
"electron": "24.2.0",
"jest": "^29.5.0",
"sass": "^1.62.1",
"typescript": "^5.0.4"
},

View file

@ -10,8 +10,9 @@ import { Log } from "./Log";
export class Safari {
static #instance: Safari;
#journalDir?: string;
#journalPattern?: string;
readonly #journalDir?: string;
readonly #journalPattern?: string;
journal?: Journal;
#watcher?: any;
@ -66,6 +67,7 @@ export class Safari {
// https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js
#getLatestJournal(): Journal|undefined {
// @ts-ignore
const journals = globSync(this.#journalPattern, {windowsPathsNoEscape: true});
const journalPath: string|undefined = _.maxBy(journals, file => fs.statSync(file).mtime);
@ -82,6 +84,7 @@ export class Safari {
watchJournalDir(): void {
const options = {usePolling: true, persistent: true, ignoreInitial: true};
// @ts-ignore
this.#watcher = chokidar.watch(this.#journalPattern, options);
this.#watcher.on('ready', () => Log.write('Watching journal folder for changes...'));

8
test/Safari.test.ts Normal file
View file

@ -0,0 +1,8 @@
import {Safari} from '../src/models/Safari';
describe('Safari', function () {
it('should return itself', () => {
const safari = Safari.start(false);
expect(safari).toBeDefined();
});
});

View file

@ -5,5 +5,5 @@
"lib": ["DOM"]
},
"include": ["src"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
}