2022-05-28 17:52:48 +00:00
|
|
|
/**
|
|
|
|
* This is a total and terrible hack that allows us to create otherwise
|
|
|
|
* uninstantiable jsdom objects. Currently this exposes a way to create
|
|
|
|
* `FileList` objects.
|
2023-11-24 14:45:55 +00:00
|
|
|
*
|
2022-05-28 17:52:48 +00:00
|
|
|
* This was inspired by felipochoa's implementation in GitHub issue:
|
|
|
|
* https://github.com/jsdom/jsdom/issues/1272. This implementation is
|
|
|
|
* "better" because it does all of the dirty work during environment
|
|
|
|
* setup. It still requires typing.
|
|
|
|
*/
|
|
|
|
|
Fix issue #187 (and upgrade jest) (#188)
* Update jest to v29.5.0
This updates jest to the latest version (29.5.0) and fixes everything
that the upgrade breaks. One of the biggest differences is that the
mock types changed and I'm once again confused as to the "proper" way
to create mocks in jest. Whatever.
* Fix issue #187 were bank writing was not working correctly
Before, `mmu.ts` would deactivate writing to the language card if
`prewrite` was reset. However, it is totally possible to reset
`prewrite` and leave writing enabled, as shown my Sather in
_Understanding the Apple IIe_, table 5.5, p. 5-24. For example:
```assembly_x86
sta $c08a ; WRITE DISABLE; READ DISABLE
lda $c08b ; PRE-WRITE set
lda $c08b ; WRITE enabled
sta $c08a ; PRE-WRITE reset; WRITE still enabled!
lda $c08b ; PRE-WRITE set; WRITE still enabled!
```
would not work correctly because the last line would clear `_writebsr`
before setting `_prewrite`, which is incorrect.
Now, `_writebsr` is only set when `_prewrite` is set and thus only
cleared when `writeSwitch` is false. This matches Table 5.5.
* Fix pre-write for the language card
This is the same issue as the `MMU`, namely that `langcard.ts` would
deactivate writing to the language card if `prewrite` was reset.
However, it is totally possible to reset `prewrite` and leave writing
enabled, as shown my Sather in _Understanding the Apple II_, table
5.4, p. 5-30. See the previous commit for an example.
This change also adds a test for the `LanguageCard` class.
2023-07-08 18:18:38 +00:00
|
|
|
import JsdomEnvironment from 'jest-environment-jsdom';
|
2022-05-28 17:52:48 +00:00
|
|
|
|
|
|
|
export default class JsdomEnvironmentWithBackDoors extends JsdomEnvironment {
|
|
|
|
async setup() {
|
|
|
|
await super.setup();
|
|
|
|
const jsdomUtils = require('jsdom/lib/jsdom/living/generated/utils');
|
|
|
|
const jsdomFileList = require('jsdom/lib/jsdom/living/generated/FileList');
|
|
|
|
|
|
|
|
this.global.backdoors = {
|
|
|
|
newFileList: (...files) => {
|
|
|
|
const impl = jsdomFileList.createImpl(this.global);
|
|
|
|
const fileList = Object.assign([...files], {
|
2023-11-24 14:45:55 +00:00
|
|
|
item: (i) => fileList[i],
|
2022-05-28 17:52:48 +00:00
|
|
|
[jsdomUtils.implSymbol]: impl,
|
|
|
|
});
|
|
|
|
impl[jsdomUtils.wrapperSymbol] = fileList;
|
2023-11-24 14:45:55 +00:00
|
|
|
const fileListCtor =
|
|
|
|
this.global[jsdomUtils.ctorRegistrySymbol].FileList;
|
2022-05-28 17:52:48 +00:00
|
|
|
Object.setPrototypeOf(fileList, fileListCtor.prototype);
|
|
|
|
return fileList;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|