Jest, use __mocks__ directory without importing it - jestjs

Currently I'm directly importing a file from __mocks__ folder which is inside src/__tests__:
import SomeComponent from '../../../../components/SomeComponent';
import personalData from '../../../../__mocks__/path/to/mock';
describe... etc
How could I use those file under __mocks__ directory without importing them? I'm pretty sure that I read in Jest documentation that if the default name of the mocks directory is __mocks__ it can't find it

Related

How to import module from node_modules?

Inside node_modules there is directory:
data/lib/
With files:
index.js
index.ts
Data.js
Data.ts
How to use this module using import?
I have tried:
import import * as d from 'data/lib';
I says that:
`index.d.ts' is not a module
File `index.d.ts' is empty
You need an index.d.ts beside the index.js. You need to generate a build from your .ts files to be able to import it in other projects. There is a property on tsconfig.json called declaration that you can set to true, and then when you call tsc to generate your build, it will create the .d.ts files automatically for you. Take a look.

How do I import a file to execute a function

I have a file with a function. I want to import the file and when doing that I get No module named ex25.
import ex25
I have checked some tutorials and the offial documentation.
import ex25
No module named ex25
First, check if the file is .py file and in the same folder with the file that you are currently working on, there shouldn't be any problem at all.
If not in the same folder, but in a different folder and make sure that your file is .py file, you need to make that folder (which contains the file) to a package by adding a file name __init__.py

Meteor Shell, can't import files from any folder: Error: Cannot find module ‘/imports/api/donuts/collection.js’

I am having some trouble importing modules into the meteor shell.
Simple example:
1.create new project (meteor create myproject)
2.create file /imports/api/donuts/collection.js and paste content:
// file: /imports/api/donuts/collection.js
import { Mongo } from 'meteor/mongo';
const Donuts = new Mongo.Collection('donuts');
export default Donuts;
3.Run meteor shell and import the file by:
import Donuts from '/imports/api/donuts/collection.js'
than this error hits up:
Error: Cannot find module '/imports/api/donuts/collection.js'
at Function.require.resolve (packages/modules-runtime.js:129:19)
at Module.resolve (packages/modules-runtime.js:81:25)
at Module.Mp.import (/home/ec2-user/.meteor/packages/modules/.0.7.7.mccaq7++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:61:29)
at repl:1:-37
at packages/shell-server/shell-server.js:458:25
at /home/ec2-user/.meteor/packages/promise/.0.8.8.i94065++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39
What's wrong? File permissions are ok, I start the meteor shell from project root.
Thanks!
Meteor originally loaded all of the source files using its default load order.
In more recent versions (circa v1.3), it treats special directories differently. One of those directories is imports.
Any directory named imports/ is not loaded anywhere and files must be imported using import.
(from the Meteor docs)
When using the shell, you can only import resources that were included in the build. If the module (file) you are trying to import is not included in your import tree (chain of imports starting somewhere outside of the /imports directory), it will not be available for import.

Typescript import ts file from node module

Maybe it's a duplicate but I've searched for an hour and haven't found the answer.
I have a node module named a-module which contains some .ts files (for example a.ts)
I have another node module b-module which has a-module among its dependencies.
I want to import some .ts file from a-module to b-module.
In some file within b-module I write:
import a = require('a-module/a');
console.log(a);
When then I'm trying to compile b-module with tsc, is says
Cannot find external module 'a-module/a'.
What am I doing wrong?
P.S. I have ArcticTypescript plugin for SublimeText, and seems that it is enough intelligent to find a-module/a. Why then tsc doesn't manage to locate my file?
P.P.S My file structure looks like that
b-module/
node_modules/
a-module/
a.ts
b.ts
I'm trying to import a.ts to b.ts.
import a = require('a-module/a');
You need to either use relative paths i.e. ../a-module/a or declare it for TypeScript explicitly i.e. declare module "a-module/a".

Is there a "default" file name that can be used for importing modules?

What I mean is if there's some standard name that can be used for the primary file in a local Nim module so that when importing by path, we can simply reference the directory?
For example, it seems right now I need to specify both the directory and file name of the local module like this:
import my_module.main
Whereas I was hoping to simply be able to reference the directory if the expected file name was found:
import my_module
Aside from using Nimble or creating a separate --path flag for every module in a nim.cfg file, is there anything that will allow this?
Also, in general, is there a conventional name to use for the main file of a module?
If I have a simple app like this:
myapp--+
|
+--myapp.nim
|
+--sub--+
|
+--sub.nim
In myapp.nim I have to use import sub.sub to load the sub-module. With import sub, I get Error: cannot open sub.
Likewise if I have modules outside the app and set the --path to the parent of those modules, I have to use import my_module.my_module.
The idea is to have a my_module.nim and sub-modules in a my_module directory. Then you can just import my_module.

Resources