Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot set property crypto of #<Object> which has only a getter #2288

Open
AndrejLES opened this issue Feb 13, 2024 · 3 comments
Open
Labels

Comments

@AndrejLES
Copy link

Problem description

Calling reset() from the appended snippet in test runs leads to

TypeError: Cannot set property crypto of #<Object> which has only a getter
    at Tabris.<anonymous> ({project}/node_modules/tabris/tabris.min.js:1:253291)
    at notifyCallback ({project}/node_modules/tabris/tabris.min.js:1:29169)
    at Tabris.[notify] ({project}/node_modules/tabris/tabris.min.js:1:28112)
    at Tabris.trigger ({project}/node_modules/tabris/tabris.min.js:1:27702)
    at Tabris._init ({project}/node_modules/tabris/tabris.min.js:1:85906)
    at reset ({project}/test/tabris-mock.ts:13:10)
    at Object.<anonymous> ({project}/test/tabris-mock.ts:94:1)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module.m._compile ({project}/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] ({project}/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> ({project}/test/integration/build-info.spec.ts:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module.m._compile ({project}/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] ({project}/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.exports.requireOrImport ({project}/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync ({project}/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync ({project}/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun ({project}/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha ({project}/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler ({project}/node_modules/mocha/lib/cli/run.js:362:11)
    at {project}/node_modules/yargs/build/index.cjs:443:71

Expected behavior

No error, test runs succeeding.

Environment

  • Tabris.js version: 3.9.0-dev.20230630 also tried with 3.9.0-dev.20240212
    tabris._init is used in test runs, until now no issues in productive code noticed

Code snippet

import { tabris } from 'tabris';
import ClientMock from 'tabris/ClientMock';

const DEFAULT_APP_VERSION = '1.0.0';
const DEFAULT_DEVICE_ORIENTATION = 'portrait';
const DEFAULT_DEVICE_PLATFORM = 'Android';
const DEFAULT_DEVICE_MODEL = 'foo';
const DEFAULT_FILESYSTEM_PATH = 'path';

export function reset() {
  const clientOptions = getDefaultMockClientOptions();
  const clientMock = new ClientMock(clientOptions);
  tabris._init(clientMock);
}

function getDefaultMockClientOptions() {
  return {
    'tabris.App': { ...getAppVersionOptions(DEFAULT_APP_VERSION) },
    'tabris.Device': { ...getDeviceOptions() },
    'tabris.FileSystem': { ...getFileSystemOptions(DEFAULT_FILESYSTEM_PATH) }
  };
}

function getFileSystemOptions(filesDir: string) {
  return {
    filesDir,
    readDir: (name: any) => {
      if (typeof name === 'string') {
        return Promise.resolve([]);
      }
      return Promise.reject('folder path should be a string');
    },
    writeFile: () => Promise.resolve(),
    readFile: () => Promise.resolve()
  };
}

function getDeviceOptions(
  platform: string = DEFAULT_DEVICE_PLATFORM,
  model: string = DEFAULT_DEVICE_MODEL,
  orientation: string = DEFAULT_DEVICE_ORIENTATION
) {
  return {
    ...getDeviceOrientationOptions(orientation),
    ...getDeviceModelOptions(model),
    ...getDevicePlatformOptions(platform)
  };
}

function getDevicePlatformOptions(platform: string) {
  return { platform };
}

function getDeviceModelOptions(model: string) {
  return { model };
}

function getDeviceOrientationOptions(orientation: string) {
  return { orientation };
}

function getAppVersionOptions(version: string) {
  return { version };
}

reset();
@AndrejLES AndrejLES added the bug label Feb 13, 2024
@tbuschto
Copy link
Member

Would be relevant to know what invironment your tests run in. I just checked, and it seems consistent with deno that window.crypto can not be set. Try using node.

@AndrejLES
Copy link
Author

AndrejLES commented Feb 16, 2024

We are using:

  • node v20.11.1
  • npm 10.2.5

Anything else you need to know?

@AndrejLES
Copy link
Author

Any further information?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants