Finally got testing working!
This commit is contained in:
parent
2a97cb358f
commit
87b631efff
9 changed files with 4205 additions and 74 deletions
1
.idea/ed-safari.iml
Executable file → Normal file
1
.idea/ed-safari.iml
Executable file → Normal file
|
@ -8,5 +8,6 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="@types/mocha" level="application" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
7
.idea/jsLibraryMappings.xml
Normal file
7
.idea/jsLibraryMappings.xml
Normal 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
6
babel.config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
['@babel/preset-env', {targets: {node: 'current'}}],
|
||||||
|
'@babel/preset-typescript',
|
||||||
|
],
|
||||||
|
};
|
10
jest.config.js
Normal file
10
jest.config.js
Normal 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
4095
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,8 @@
|
||||||
"package": "electron-forge package",
|
"package": "electron-forge package",
|
||||||
"make": "electron-forge make",
|
"make": "electron-forge make",
|
||||||
"publish": "electron-forge publish",
|
"publish": "electron-forge publish",
|
||||||
"lint": "echo \"No linting configured\""
|
"lint": "echo \"No linting configured\"",
|
||||||
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": {
|
"author": {
|
||||||
|
@ -22,6 +23,9 @@
|
||||||
"node 18"
|
"node 18"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"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/cli": "^6.1.1",
|
||||||
"@electron-forge/maker-deb": "^6.1.1",
|
"@electron-forge/maker-deb": "^6.1.1",
|
||||||
"@electron-forge/maker-rpm": "^6.1.1",
|
"@electron-forge/maker-rpm": "^6.1.1",
|
||||||
|
@ -30,12 +34,15 @@
|
||||||
"@electron-forge/plugin-vite": "^6.1.1",
|
"@electron-forge/plugin-vite": "^6.1.1",
|
||||||
"@tsconfig/node-lts": "^18.12.2",
|
"@tsconfig/node-lts": "^18.12.2",
|
||||||
"@tsconfig/node20": "^1.0.0",
|
"@tsconfig/node20": "^1.0.0",
|
||||||
|
"@types/jest": "^29.5.1",
|
||||||
"@types/lodash-es": "^4.17.7",
|
"@types/lodash-es": "^4.17.7",
|
||||||
"@types/node": "^20.1.2",
|
"@types/node": "^20.1.2",
|
||||||
"@types/tail": "^2.2.1",
|
"@types/tail": "^2.2.1",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.14",
|
||||||
|
"babel-jest": "^29.5.0",
|
||||||
"browserslist": "^4.21.5",
|
"browserslist": "^4.21.5",
|
||||||
"electron": "24.2.0",
|
"electron": "24.2.0",
|
||||||
|
"jest": "^29.5.0",
|
||||||
"sass": "^1.62.1",
|
"sass": "^1.62.1",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,89 +9,92 @@ import { Journal } from "./Journal";
|
||||||
import { Log } from "./Log";
|
import { Log } from "./Log";
|
||||||
|
|
||||||
export class Safari {
|
export class Safari {
|
||||||
static #instance: Safari;
|
static #instance: Safari;
|
||||||
#journalDir?: string;
|
|
||||||
#journalPattern?: string;
|
|
||||||
journal?: Journal;
|
|
||||||
|
|
||||||
#watcher?: any;
|
readonly #journalDir?: string;
|
||||||
|
readonly #journalPattern?: string;
|
||||||
|
journal?: Journal;
|
||||||
|
|
||||||
private constructor(isPackaged: boolean) {
|
#watcher?: any;
|
||||||
if (!isPackaged && os.platform() === 'linux') { // Account for WSL during development
|
|
||||||
this.#journalDir = "/mnt/c/Users/marle/Saved\ Games/Frontier\ Developments/Elite\ Dangerous/";
|
|
||||||
|
|
||||||
} else if (os.platform() === 'win32') { // Windows
|
private constructor(isPackaged: boolean) {
|
||||||
this.#journalDir = path.join(
|
if (!isPackaged && os.platform() === 'linux') { // Account for WSL during development
|
||||||
os.homedir(),
|
this.#journalDir = "/mnt/c/Users/marle/Saved\ Games/Frontier\ Developments/Elite\ Dangerous/";
|
||||||
'Saved Games',
|
|
||||||
'Frontier Developments',
|
|
||||||
'Elite Dangerous'
|
|
||||||
);
|
|
||||||
|
|
||||||
} else if (os.platform() === 'linux') { // Linux
|
} else if (os.platform() === 'win32') { // Windows
|
||||||
this.#journalDir = path.join(
|
this.#journalDir = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
'.local',
|
'Saved Games',
|
||||||
'share',
|
'Frontier Developments',
|
||||||
'Steam',
|
'Elite Dangerous'
|
||||||
'steamapps',
|
);
|
||||||
'compatdata',
|
|
||||||
'359320',
|
|
||||||
'pfx',
|
|
||||||
'drive_c',
|
|
||||||
'steamuser',
|
|
||||||
'Saved Games',
|
|
||||||
'Frontier Developments',
|
|
||||||
'Elite Dangerous',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
Log.write(`ERROR: Journal files not found. OS: ${os.platform()}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.#journalDir) {
|
} else if (os.platform() === 'linux') { // Linux
|
||||||
this.#journalPattern = path.join(this.#journalDir, 'Journal.*.log');
|
this.#journalDir = path.join(
|
||||||
this.journal = this.#getLatestJournal();
|
os.homedir(),
|
||||||
}
|
'.local',
|
||||||
|
'share',
|
||||||
|
'Steam',
|
||||||
|
'steamapps',
|
||||||
|
'compatdata',
|
||||||
|
'359320',
|
||||||
|
'pfx',
|
||||||
|
'drive_c',
|
||||||
|
'steamuser',
|
||||||
|
'Saved Games',
|
||||||
|
'Frontier Developments',
|
||||||
|
'Elite Dangerous',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Log.write(`ERROR: Journal files not found. OS: ${os.platform()}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static start(isPackaged: boolean): Safari {
|
if (this.#journalDir) {
|
||||||
if (!Safari.#instance) {
|
this.#journalPattern = path.join(this.#journalDir, 'Journal.*.log');
|
||||||
Safari.#instance = new Safari(isPackaged);
|
this.journal = this.#getLatestJournal();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Safari.#instance;
|
static start(isPackaged: boolean): Safari {
|
||||||
|
if (!Safari.#instance) {
|
||||||
|
Safari.#instance = new Safari(isPackaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------- #getLatestJournal ---- */
|
return Safari.#instance;
|
||||||
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js
|
/* ------------------------------------------------------------------- #getLatestJournal ---- */
|
||||||
#getLatestJournal(): Journal|undefined {
|
|
||||||
const journals = globSync(this.#journalPattern, {windowsPathsNoEscape: true});
|
|
||||||
const journalPath: string|undefined = _.maxBy(journals, file => fs.statSync(file).mtime);
|
|
||||||
|
|
||||||
if (journalPath) {
|
// https://stackoverflow.com/questions/15696218/get-the-most-recent-file-in-a-directory-node-js
|
||||||
Log.write(`New journal file found, now watching ${path.basename(journalPath)}.`);
|
#getLatestJournal(): Journal|undefined {
|
||||||
return new Journal(journalPath);
|
// @ts-ignore
|
||||||
} else {
|
const journals = globSync(this.#journalPattern, {windowsPathsNoEscape: true});
|
||||||
Log.write('ERROR: Unable to find latest journal.');
|
const journalPath: string|undefined = _.maxBy(journals, file => fs.statSync(file).mtime);
|
||||||
return;
|
|
||||||
}
|
if (journalPath) {
|
||||||
|
Log.write(`New journal file found, now watching ${path.basename(journalPath)}.`);
|
||||||
|
return new Journal(journalPath);
|
||||||
|
} else {
|
||||||
|
Log.write('ERROR: Unable to find latest journal.');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- watchJournalDir ---- */
|
/* --------------------------------------------------------------------- watchJournalDir ---- */
|
||||||
|
|
||||||
watchJournalDir(): void {
|
watchJournalDir(): void {
|
||||||
const options = {usePolling: true, persistent: true, ignoreInitial: true};
|
const options = {usePolling: true, persistent: true, ignoreInitial: true};
|
||||||
this.#watcher = chokidar.watch(this.#journalPattern, options);
|
// @ts-ignore
|
||||||
|
this.#watcher = chokidar.watch(this.#journalPattern, options);
|
||||||
|
|
||||||
this.#watcher.on('ready', () => Log.write('Watching journal folder for changes...'));
|
this.#watcher.on('ready', () => Log.write('Watching journal folder for changes...'));
|
||||||
this.#watcher.on('add', () => this.journal = this.#getLatestJournal());
|
this.#watcher.on('add', () => this.journal = this.#getLatestJournal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- shutdown ---- */
|
/* ---------------------------------------------------------------------------- shutdown ---- */
|
||||||
|
|
||||||
async shutdown(): Promise<void> {
|
async shutdown(): Promise<void> {
|
||||||
this.journal?.shutdown();
|
this.journal?.shutdown();
|
||||||
await this.#watcher.close();
|
await this.#watcher.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
test/Safari.test.ts
Normal file
8
test/Safari.test.ts
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,5 +5,5 @@
|
||||||
"lib": ["DOM"]
|
"lib": ["DOM"]
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue