This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
2021-06-11 00:47:09 -04:00
|
|
|
import {Frigid, RESTORE} from '../out/index.js';
|
|
|
|
|
import { existsSync, readFileSync, unlinkSync } from 'fs';
|
|
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
|
|
|
|
const trackingData = {
|
|
|
|
|
constructorCalls: 0,
|
|
|
|
|
restoreCalls: 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Test extends Frigid {
|
|
|
|
|
foo = 'bar';
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
trackingData.constructorCalls ++;
|
2021-06-11 00:49:37 -04:00
|
|
|
console.log('construct')
|
2021-06-11 00:47:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RESTORE]() {
|
|
|
|
|
trackingData.restoreCalls ++;
|
2021-06-11 00:49:37 -04:00
|
|
|
console.log('restore')
|
2021-06-11 00:47:09 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filepath = 'test.state.json';
|
|
|
|
|
|
|
|
|
|
if(existsSync(filepath)) {
|
|
|
|
|
unlinkSync(filepath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const test = Test.create(filepath)
|
|
|
|
|
|
|
|
|
|
expect(test.sync.bind(test)).to.not.throw();
|
|
|
|
|
|
|
|
|
|
expect(existsSync(filepath)).to.be.true;
|
|
|
|
|
expect(readFileSync(filepath).toString()).to.not.be.empty;
|
|
|
|
|
|
|
|
|
|
expect(trackingData.constructorCalls).to.equal(1);
|
|
|
|
|
expect(trackingData.restoreCalls).to.equal(1);
|
|
|
|
|
|
|
|
|
|
const retest = Test.create(filepath);
|
|
|
|
|
|
2021-06-11 01:01:28 -04:00
|
|
|
expect(trackingData.constructorCalls).to.equal(2);
|
2021-06-11 00:49:37 -04:00
|
|
|
expect(trackingData.restoreCalls).to.equal(2);
|
|
|
|
|
|
|
|
|
|
unlinkSync(filepath)
|