diff --git a/jest.config.js b/jest.config.js index f6153f8a..ef8c050a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,97 +1,7 @@ module.exports = { clearMocks: true, coverageDirectory: "coverage", - - // An array of regexp pattern strings used to skip coverage collection - coveragePathIgnorePatterns: [ - "node_modules" - ], - - // An array of directory names to be searched recursively up from the requiring module's location - // moduleDirectories: [ - // "node_modules" - // ], - - // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], - - // Reset the module registry before running each individual test - // resetModules: false, - - // A path to a custom resolver - // resolver: null, - - // The root directory that Jest should scan for tests and modules within - //rootDir: "tests", - - // A list of paths to directories that Jest should use to search for files in - // roots: [ - // "" - // ], - - // The paths to modules that run some code to configure or set up the testing environment before each test - // setupFiles: [], - - // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], - - // A list of paths to snapshot serializer modules Jest should use for snapshot testing - // snapshotSerializers: [], - - // The test environment that will be used for testing - testEnvironment: "node", - - // Options that will be passed to the testEnvironment - // testEnvironmentOptions: {}, - - // Adds a location field to test results - // testLocationInResults: false, - - // The glob patterns Jest uses to detect test files - // testMatch: [ - // "**/__tests__/**/*.[jt]s?(x)", - // "**/?(*.)+(spec|test).[tj]s?(x)" - // ], - - // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - testPathIgnorePatterns: [ - "node_modules" - ], - - // The regexp pattern or array of patterns that Jest uses to detect test files - testRegex: [ - "\\.test\\.js$" - ], - - // This option allows the use of a custom results processor - // testResultsProcessor: null, - - // This option allows use of a custom test runner - // testRunner: "jasmine2", - - // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href - // testURL: "http://localhost", - - // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" - // timers: "real", - - // A map from regular expressions to paths to transformers - // transform: null, - - // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - // transformIgnorePatterns: [ - // "\\\\node_modules\\\\" - // ], - - // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them - // unmockedModulePathPatterns: undefined, - - // Indicates whether each individual test should be reported during the run - verbose: true, - - // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode - // watchPathIgnorePatterns: [], - - // Whether to use watchman for file crawling - // watchman: true, + collectCoverage: true, + coverageProvider: "v8", + testEnvironment: "jsdom", }; diff --git a/package.json b/package.json index c2b1603e..499ba1e5 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "build": "rollup -c", "webgl": "rollup -c --environment entry:webgl", "core": "rollup -c --environment entry:core", - "test": "jest --coverage", + "test": "jest --env=jsdom", "lint": "eslint src/og", - "generate_types": "tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir node_modules/@types/openglobus__og", + "generate_types": "rm -rf node_modules/@types/openglobus__og; tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir node_modules/@types/openglobus__og", "prepare": "husky install" }, "repository": { @@ -52,7 +52,7 @@ "eslint-plugin-standard": "^4.1.0", "husky": "^6.0.0", "jaguarjs-jsdoc": "^1.1.0", - "jest": "^26.6.3", + "jest": "^27.2.3", "jsdoc": "^3.6.7", "lint-staged": "^11.0.0", "local-web-server": "^5.1.1", diff --git a/tests/classes.test.js b/tests/classes.test.js new file mode 100644 index 00000000..d18407f8 --- /dev/null +++ b/tests/classes.test.js @@ -0,0 +1,22 @@ +import { Planet } from '../src/og/scene/Planet.js'; +import { SegmentLonLat } from '../src/og/segment/SegmentLonLat.js'; +import { Worker } from './worker'; + +window.Worker = Worker; +global.URL.createObjectURL = jest.fn(() => ''); + +const mockPlanet = () => { + const planet = new Planet(); + planet.renderer = {}; + planet.terrain = { gridSizeByZoom: {} }; + return planet; +} + +const mockExtent = () => { + return { southWest: { forwardMercatorEPS01: () => { } }, northEast: { forwardMercatorEPS01: () => { } } }; +} + +test('Testing SegmentLonLat', () => { + const segmentLonLat = new SegmentLonLat({}, mockPlanet(), {}, mockExtent()); + expect(segmentLonLat).toBeTruthy(); +}); \ No newline at end of file diff --git a/tests/test.test.js b/tests/test.test.js deleted file mode 100644 index 4f37fef1..00000000 --- a/tests/test.test.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -test('Waiting for tests', () => { - expect(true).toBe(true); -}); \ No newline at end of file diff --git a/tests/worker.js b/tests/worker.js new file mode 100644 index 00000000..b731423d --- /dev/null +++ b/tests/worker.js @@ -0,0 +1,14 @@ +export class Worker { + constructor(stringUrl) { + this.url = stringUrl; + this.onmessage = () => { }; + } + + postMessage(msg) { + this.onmessage(msg); + } +} + +export class URL { + createObjectURL(tmp) { return '' } +} \ No newline at end of file