abhsarma / milliways

MIT License
0 stars 0 forks source link

Testing Svelte Components #55

Open hwangkyle opened 1 year ago

hwangkyle commented 1 year ago

It seems like using Jest for testing Svelte components requires a lot of moving parts. I will document what I have done here:

svelte.config.cjs

I put this in a separate file since it seems cleaner to do so.

module.exports = {
    "testEnvironment": "jsdom",
    "transform": {
        "^.+\\.js$": "babel-jest",
        "^.+\\.svelte$": ["svelte-jester",{"preprocess": true}]
    },
    "transformIgnorePatterns": [
        "node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
    ],
    "moduleFileExtensions": ["js","svelte","json"],
    "moduleNameMapper": {
        "^.+\\.(gif|png)$": "<rootDir>/mocks/fileMock.js"
    }
};
hwangkyle commented 1 year ago

Here are some stackoverflow references. Not all were necessarily used, but they could be helpful. https://stackoverflow.com/questions/49501723/unexpected-token-m-in-json-at-position-0-error https://stackoverflow.com/questions/75809272/referenceerror-broadcastchannel-is-not-defined-using-jest-testing-libray https://stackoverflow.com/questions/64605154/jest-domock-and-json-import-mocking https://stackoverflow.com/questions/69227566/consider-using-the-jsdom-test-environment https://stackoverflow.com/questions/70588096/error-in-svelte-config-js-syntax-error-cannot-use-import-statement-outside-a-mo https://stackoverflow.com/questions/73607410/referenceerror-structuredclone-is-not-defined-using-jest-with-nodejs-typesc https://stackoverflow.com/questions/39418555/syntaxerror-with-jest-and-react-and-importing-css-files https://stackoverflow.com/questions/56103772/syntaxerror-unexpected-token-m-in-json-at-position-0-jest-fails-running-tests https://stackoverflow.com/questions/42986480/jest-mock-import-of-json-file