Title: Importing a test helper into global namespace
Tags: typescript;mocha.js;typescript2.0
Question: I want to define a test helper -- ```test-helper.ts``` -- which sets up with global set of test file dependencies and later will also add some utility functions. Something like this:

```import 'mocha';
import * as chai from 'chai';
import * as Promise from "bluebird";
import './testing/test-console'; // TS declaration
import '../src/shared/base-defs';
import { stdout, stderr } from 'test-console';

const expect = chai.expect;

function prepareEnv(env) { ... }
```

In the test file ```test-spec.ts``` I'd like to import the helper file with something like:

```import 'test-helper';
declare('my tests', () =&gt; { ... }
```

and have the mocha, chai, and other globally loaded dependencies loaded into the global namespace for the test file. Is this possible? I'd also like to be able to have my helper functions like ```prepareEnv()``` available ... either in the global namespace or maybe more ideally in a helper namespace. Maybe I can use something like the following to achieve this last part?

```declare namespace Helpers { ... }
```

and put the function into it?



added

It would be appear functions can not be implemented in ambient contexts so my idea about declaring a namespace should be ignored. Instead I am importing a ```test-functions.ts``` in the ```test-helper.ts``` file:

```import * as helpers from './testing/test-functions.ts';
```

That's probably a step in the right direction but the main problem remains which is keeping the ambient/global declarations in the ```test-helper.ts``` file available to test files like ```test-spec.ts```;


Here is the accepted answer: You need to do global augmentation in this case:

https://www.typescriptlang.org/docs/handbook/declaration-merging.html

But in general, get away from namespacing! :)



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:06/23/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<typescript><mocha.js><typescript2.0>', 'Title': 'Importing a test helper into global namespace', 'ViewCount': 350, 'id': 44730485, 'user_AboutMe': '<p>An "older developer" who got out of coding and into senior management but has decided to come back out of the clouds and get dirty again with code. Happy days. :^)</p>\n', 'user_AccountId': 1382315.0, 'user_DisplayName': 'ken', 'user_Reputation': 8401.0, 'user_Views': 819.0, 'user_id': 1315053.0}}