Telling Jest to not mock /moment(-timezone)?/ not working - unit-testing

Getting an error with jest where anytime moment/moment.tz() is called, TypeError: (0 , _moment2.default)(...).tz is not a function is thrown. Below is my jest config with absolute paths redacted.
{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "<absolute path>",
"clearMocks": true,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"globals": {
"window": true
},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": [
[
"^#/(.*)$",
"/<absolute path>/src/$1"
],
[
"\\.(css|less)$",
"/<absolute path>/test/__mocks__/styleMock.js"
]
],
"modulePathIgnorePatterns": [],
"name": "79986797be68f3008e950f2cefe0bbd1",
"resetMocks": false,
"resetModules": false,
"rootDir": "<absolute path>",
"roots": [
"<absolute path>/src",
"<absolute path>/test"
],
"runner": "jest-runner",
"setupFiles": [],
"snapshotSerializers": [
"/<absolute path>/node_modules/jest-serializer-html/index.js"
],
"testEnvironment": "jest-environment-jsdom",
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)(spec|test).js?(x)"
],
"testPathIgnorePatterns": [
"node_modules/",
"test/e2e/"
],
"testRegex": "",
"testRunner": "/<absolute path>/node_modules/jest-jasmine2/build/index.js",
"testURL": "about:blank",
"timers": "real",
"transform": [
[
".*\\.(vue)$",
"/<absolute path>/node_modules/vue-jest/vue-jest.js"
],
[
".*\\.js$",
"/opt/cm/cm_frontend/cm/node_modules/babel-jest/build/index.js"
]
],
"transformIgnorePatterns": [
"/node_modules/"
],
"unmockedModulePathPatterns": [
"moment",
"moment-timezone"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": false,
"changedFilesWithAncestor": false,
"collectCoverage": true,
"collectCoverageFrom": [
"src/components/**/*.{js,vue}",
"src/mixins/**/*.js",
],
"coverageDirectory": "<ABSOLUTE PATH>",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"expand": false,
"listTests": false,
"mapCoverage": true,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"rootDir": "<ROOT PATH HERE>",
"runTestsByPath": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": false,
"watch": false,
"watchman": true
},
"version": "21.2.1"
}
I've tried telling jest to jest.dontMock() as well as jest.unmock() but to no avail.
I've also tried require.requireActual().
I want to only mock moment when I specify per test (per file) with jest.mock().
What could be causing these issues? I am not mocking or unmocking moment anywhere in my test files. I've just simply used #vue/test-utils to mock entire computed properties using moment to get around this issue in the meantime.

You could try importing them directly in the tests. Also, I checked issues and other questions and it seems that importing timezone doesn't actually add the tz function to moment, so a way to solve it could be:
import moment from "moment-timezone"

Related

Task in ECS not being called by Step Functions

I have a DAG in Step Functions which is executed by an app within an ECS container. This DAG is scheduled to run every day. I'm seeing the following behavior:
Some random tasks fail with States. Timeout error (the timeout is set to 30 min)
I couldn't find the CloudWatch logs for these tasks that failed. This indicates that the tasks itself are never called.
Why this happens? Is there any setting I can use to prevent such behavior? Below follows the task code:
Input:
.
{
"version": "0",
"id": "ff4a2a37-7024-a213-70f0-11df9104484a",
"detail-type": "Scheduled Event",
"source": "aws.events",
"account": "",
"time": "2022-11-22T08:30:00Z",
"region": "us-east-1",
"resources": [
"arn:aws:events:rule/bi-datalake-hml"
],
"detail": {}
}
Output:
.
{
"Failures": [],
"SdkHttpMetadata": {
"AllHttpHeaders": {
"x-amzn-RequestId": [
"50737371-c24f-4901-98a5-bdef19278cf8"
],
"Content-Length": [
"2224"
],
"Date": [
"Tue, 22 Nov 2022 08:30:46 GMT"
],
"Content-Type": [
"application/x-amz-json-1.1"
]
},
"HttpHeaders": {
"Content-Length": "2224",
"Content-Type": "application/x-amz-json-1.1",
"Date": "Tue, 22 Nov 2022 08:30:46 GMT",
"x-amzn-RequestId": "50737371-c24f-4901-98a5-bdef19278cf8"
},
"HttpStatusCode": 200
},
"SdkResponseMetadata": {
"RequestId": "50737371-c24f-4901-98a5-bdef19278cf8"
},
"Tasks": [
{
"Attachments": [
{
"Details": [
{
"Name": "subnetId",
"Value": "subnet-62d7664e"
}
],
"Id": "eacd4cdf-3ce8-4927-a869-52eb71f553b3",
"Status": "PRECREATED",
"Type": "ElasticNetworkInterface"
}
],
"Attributes": [
{
"Name": "ecs.cpu-architecture",
"Value": "x86_64"
}
],
"AvailabilityZone": "us-east-1c",
"ClusterArn": "arn:aws::cluster/bi-datalake-hml",
"Containers": [
{
"ContainerArn": "arn::container/bi-datalake-hml/ad12e4d9017443d889055024d1932ddf/eb1c44d5-01b8-4c52-8950-8676b6ecd949",
"Cpu": "0",
"GpuIds": [],
"Image": ".dkr.ecr.us-east-1.amazonaws.com/bi_dbtoncloud_hml:latest",
"LastStatus": "PENDING",
"ManagedAgents": [],
"Name": "bi_dbtoncloud_hml",
"NetworkBindings": [],
"NetworkInterfaces": [],
"TaskArn": "arn:aws:ecs:us-east-1::task/bi-datalake-hml/ad12e4d9017443d889055024d1932ddf"
}
],
"Cpu": "256",
"CreatedAt": 1669105846495,
"DesiredStatus": "RUNNING",
"EnableExecuteCommand": false,
"EphemeralStorage": {
"SizeInGiB": 20
},
"Group": "family:bi_dbtoncloud_hml",
"InferenceAccelerators": [],
"LastStatus": "PROVISIONING",
"LaunchType": "FARGATE",
"Memory": "1024",
"Overrides": {
"ContainerOverrides": [
{
"Command": [],
"Environment": [
{
"Name": "DBT_MODEL_TO_RUN",
"Value": "alpha_order_address_shipping"
},
{
"Name": "TASK_TOKEN",
"Value": "AQCIAAAAKgAAAAMAAAAAAAAAAaP+z4q5FgxDHKZhHvzNF0PDV8l/5AkxTlorAGbQfnjdDJE1P1NWf+Jj1OINDelJ0RLrsAtdwIDJcAFmehGFj9mGJ905+T9sdWmKbsSjHuR0fCksAw==vIiI8wfR+LDUo1zPl03VOvkCHUeD5mzrDBoyjVRpA7QuqJ8ocA5OmVSN6MEGg3eS24H/3m3/MZRbmRNydbvI5DIB9PDD5seYIJamDTlfqEtYESgxWBoPrlVmvuphEnw5orSIeh5sZpsKm3/AlzB4OsoZaJleWBd+1WQbWclKEpV9bG3aKCsJO5rYyVaI7Ik09lTrogpL0VeulC2q/rY4cXR/r3lPA9ZL9YalUXgqij2ZuZIRby63hEjzTcoIkieMQMRcRd7XmKb1p8LsE2nSfSRnRotn9JeKVn7/4UBmWx0iQUd/14Dw1TXUSDwUx0sAPN7dtv2RdnqdLfJI6LoJnuPagkySFTaPOsJ0jpgLi9cjsJMVlWboCXlH57fj0JNosDLisxYlf5R3lB4paspZ8DHfgfAW5Saywc/KCCby7wfyYvVKpXvsJFIoBdtXaXs9tlbyTmlg9Dy9Oaol33ZFhVrOuDTzgDf4x6Mguxz1cQEaze8Ui0G2NDCoNxPU+WffSkrsb0Pflf5LsPfHAuI2"
},
{
"Name": "DBT_ENV",
"Value": "hml"
}
],
"EnvironmentFiles": [],
"Name": "bi_dbtoncloud_hml",
"ResourceRequirements": []
}
],
"InferenceAcceleratorOverrides": []
},
"PlatformFamily": "Linux",
"PlatformVersion": "1.4.0",
"Tags": [],
"TaskArn": "arn:aws:ecs:us-east-1::task/bi-datalake-hml/ad12e4d9017443d889055024d1932ddf",
"TaskDefinitionArn": "arn:aws:ecs:us-east-1::task-definition/bi_dbtoncloud_hml:2",
"Version": 1
}
]
}
If you need more information, please let me know.

What is causing this Invalid JSON ABI structure error?

I'm trying to deploy an ink! contract through polkadotJS.
var WASM = fs.readFileSync('./resources/flipper.wasm');
var ABI = fs.readFileSync('./resources/metadata.json');
const api = await ApiPromise.create();
const code = new CodePromise(api,ABI,WASM);
When executing, I get this error:
Error: Invalid JSON ABI structure supplied, expected a recent metadata version
According to Polkadot, the error is caused by a version lower than 3.0-rc1. Yet my version is ink! 3.0.0-rc3
my abi:
{
"metadataVersion": "0.1.0",
"source": {
"hash": "0x7fbad529eb12d718da29468d27aa3f7b202bec25411f58d32999166ff614cf7f",
"language": "ink! 3.0.0-rc3",
"compiler": "rustc 1.53.0-nightly"
},
"contract": {
"name": "flipper",
"version": "0.1.0",
"authors": [
"[your_name] <[your_email]>"
]
},
"spec": {
"constructors": [
{
"args": [
{
"name": "init_value",
"type": {
"displayName": [
"bool"
],
"type": 1
}
}
],
"docs": [
"Constructor that initializes the `bool` value to the given `init_value`."
],
"name": [
"new"
],
"selector": "0x9bae9d5e"
},
{
"args": [],
"docs": [
"Constructor that initializes the `bool` value to `false`.",
"",
"Constructors can delegate to other constructors."
],
"name": [
"default"
],
"selector": "0xed4b9d1b"
}
],
"docs": [],
"events": [],
"messages": [
{
"args": [],
"docs": [
" A message that can be called on instantiated contracts.",
" This one flips the value of the stored `bool` from `true`",
" to `false` and vice versa."
],
"mutates": true,
"name": [
"flip"
],
"payable": false,
"returnType": null,
"selector": "0x633aa551"
},
{
"args": [],
"docs": [
" Simply returns the current value of our `bool`."
],
"mutates": false,
"name": [
"get"
],
"payable": false,
"returnType": {
"displayName": [
"bool"
],
"type": 1
},
"selector": "0x2f865bd9"
}
]
},
"storage": {
"struct": {
"fields": [
{
"layout": {
"cell": {
"key": "0x0000000000000000000000000000000000000000000000000000000000000000",
"ty": 1
}
},
"name": "value"
}
]
}
},
"types": [
{
"def": {
"primitive": "bool"
}
}
]
}
So my ink! version is not the issue, what else is causing this? Or am I maybe doing something else wrong?
So when I imported the .contract file like this
var contract = fs.readFileSync('./resources/flipper.contract');
const json = u8aToString(contract);
const ABI = new Abi(json, api.registry.getChainProperties());
the error was solved! I used the contract blob instead of the wasm and abi json

Jest - No tests found

I have specific situation. I have something like common module that define common behaviour of all integrations and all integrations is using that as a library. In that common module, I have configuration of jest and set of tests.
Everything works OK in case that common module is linked (npm link) to integration. But when this this common module is installed directly from npm, jest is not able to find any tests. I suppose, there are some files ignored, but I was not abe to find any configuration that would solve this situation.
Final configuration from debug mode looks like this:
{
"configs": [
{
"automock": false,
"cache": true,
"cacheDirectory": "/private/var/folders/mv/v_zhxfq113qf8d6vsf4ldwq80000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "<path>/Workspace/integration/my_integration",
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"extraGlobals": [],
"forceCoverageMatch": [],
"globals": {},
"haste": {
"computeSha1": false,
"throwOnModuleCollision": false
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"ts",
"tsx",
"node"
],
"moduleNameMapper": [],
"modulePathIgnorePatterns": [],
"name": "24eedccdafdba030f3d9209ab1064c8e",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"restoreMocks": false,
"rootDir": "<path>/Workspace/integration/my_integration/node_modules/common_module/tests/api",
"roots": [
"<path>/Workspace/integration/my_integration/node_modules/common_module/tests/api"
],
"runner": "jest-runner",
"setupFiles": [],
"setupFilesAfterEnv": [],
"skipFilter": false,
"slowTestThreshold": 5,
"snapshotSerializers": [],
"testEnvironment": "<path>/Workspace/integration/my_integration/node_modules/jest-environment-node/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [],
"testRunner": "<path>/Workspace/integration/my_integration/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [],
"transformIgnorePatterns": [
"/node_modules/",
"\\.pnp\\.[^\\/]+$"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "<path>/Workspace/integration/my_integration/node_modules/common_module/coverage",
"coverageProvider": "babel",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"findRelatedTests": false,
"forceExit": false,
"json": false,
"lastCommit": false,
"listTests": false,
"logHeapUsage": false,
"maxConcurrency": 5,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"onlyFailures": false,
"passWithNoTests": false,
"projects": [],
"rootDir": "<path>/Workspace/integration/my_integration/node_modules/common_module/tests/api",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testSequencer": "<path>/Workspace/integration/my_integration/node_modules/#jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"verbose": true,
"watch": false,
"watchAll": false,
"watchman": true
},
"version": "26.4.0"
}
All tests are defined on path <path>/Workspace/integration/my_integration/node_modules/common_module/tests/api named as e.g. something.test.js.
Console will show allways:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
No files found in <path>/Workspace/integration/my_integration/node_modules/common_module/tests/api.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Pattern: - 0 matches
npm ERR! Test failed. See above for more details.

ECR Task definition: Container links should not have a cycle?

I'm using AWS-CLI to register an ECR task definition. My task definition is like follows:
{
"family": "",
"taskRoleArn": "",
"executionRoleArn": "",
"networkMode": "none",
"containerDefinitions": [
{
"name": "",
"image": "",
"cpu": 0,
"memory": 0,
"memoryReservation": 0,
"links": [
""
],
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"essential": true,
"entryPoint": [
""
],
"command": [
""
],
"environment": [
{
"name": "",
"value": ""
}
],
"mountPoints": [
{
"sourceVolume": "",
"containerPath": "",
"readOnly": true
}
],
"volumesFrom": [
{
"sourceContainer": "",
"readOnly": true
}
],
"linuxParameters": {
"capabilities": {
"add": [
""
],
"drop": [
""
]
},
"devices": [
{
"hostPath": "",
"containerPath": "",
"permissions": [
"mknod"
]
}
],
"initProcessEnabled": true
},
"hostname": "",
"user": "",
"workingDirectory": "",
"disableNetworking": true,
"privileged": true,
"readonlyRootFilesystem": true,
"dnsServers": [
""
],
"dnsSearchDomains": [
""
],
"extraHosts": [
{
"hostname": "",
"ipAddress": ""
}
],
"dockerSecurityOptions": [
""
],
"dockerLabels": {
"KeyName": ""
},
"ulimits": [
{
"name": "fsize",
"softLimit": 0,
"hardLimit": 0
}
],
"logConfiguration": {
"logDriver": "syslog",
"options": {
"KeyName": ""
}
}
}
],
"volumes": [
{
"name": "",
"host": {
"sourcePath": ""
}
}
],
"placementConstraints": [
{
"type": "memberOf",
"expression": ""
}
],
"requiresCompatibilities": [
"EC2"
],
"cpu": "10",
"memory": "600"
}
, which is basically almost identical to the auto-generated skeleton:
aws ecs register-task-definition --generate-cli-skeleton
But it looks that when using the command
aws ecs register-task-definition --family taskDef --cli-input-json taskDef-v1.json --region us-east-2
I get this:
An error occurred (ClientException) when calling the RegisterTaskDefinition operation: Container links should not have a cycle
What am I doing wrong?
That particular error is caused because you have empty links defined:
"links": [
""
]
The CLI skeleton is a template you need to edit - it has many empty values for fields that are not required. The minimum task definition template is something like:
{
"containerDefinitions": [
{
"name": "my-task-name",
"image": "my-registry/my-image",
"memoryReservation": 256,
"cpu": 256
}
]
}

using chutzpah and jasmine with typescript and systemjs

I am having trouble getting an import working in a jasmine unit test that is written in typescript. Chutzpah is throwing an error on the import statement - which in js gets translated to a define
import {fakeclass} from '../src/data-analysis/fakeclass';
The error I see is:
Error: ReferenceError: Can't find variable: define
Otherwise the test gets discovered and runs fine.
I assume it has to with systemjs not being loaded by chutzpah - is there a recommended way to set this up?
here is my chutzpah.json file
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "Normal",
"TypeScriptModuleKind": "CommonJS",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ]
},
"References": [
{
"Includes": [ "src/*.ts" ],
"Excludes": [ "src/*.d.ts" ]
},
{
"Path": "./jspm_packages/system.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./jspm_packages/system-polyfills.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./config.js",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Includes": [ "*/test/*.ts" ],
"Excludes": [ "*/test/*.d.ts" ]
}
]}
I took a look at the sample you gave me and got it working by following the pattern in the Chutzpah Angular2 sample.
config.js
System.config({
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"es7.decorators",
"runtime"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
map: {
}
});
chutzpah.json
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ]
},
"References": [
{
"Path": "./jspm_packages/system.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./jspm_packages/system-polyfills.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./config.js",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Includes": [ "*/test/*.ts" ],
"Excludes": [ "*/test/*.d.ts" ]
}
],
"Server": {
"Enabled": true
}
}