If you're open to using the esm module 
<https://github.com/standard-things/esm>, you don't need to use the .mjs 
extension, or Babel for that matter. 

Once you've installed esm, you just have to do something like: mocha -r esm 
[test glob pattern]

I just wrote a blogpost about this actually, check it out if you want more 
information 
<https://www.coreycleary.me/how-to-use-import-export-in-node-without-babel/>, 
but that's the gist of it.

Now, for CircleCI, I like to have two test scripts in my package.json, one 
for CI and one for local dev, like so:

"test": "NODE_ENV=test mocha -r esm --watch ./tests/**/*.test.js",
"test:ci": "NODE_ENV=test mocha -r esm ./tests/**/*.test.js",

That way you can run tests in watch mode for local dev and have them run 
normally on CI (obviously you don't want tests running in watch mode on CI 
as they won't exit and the build will never complete).

Here's a sample CircleCI config you can leverage:

version: 2

defaults: &defaults
  working_directory: ~/repo
  docker:
    - image: circleci/node:10.14.2

jobs:
  core:
    <<: *defaults
    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: npm install

      - run: npm lint

      - run: npm run test:ci # notice, we use the test:ci script here not the 
test in watch mode script

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      
      - persist_to_workspace:
          root: ~/repo
          paths: .

workflows:
  version: 2
  core:
    jobs:
      - core:
          filters:
            branches:
              only:
                - master


On Friday, October 18, 2019 at 12:46:37 PM UTC-5, Nnamdi Okpala wrote:
>
>
> I am creating the backend aka api of my digital portfolio and want to:
>
> 1) Offload tests for another process
> 2) perform the test in circleci
> 3) most important run the test with mjs
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/a315ed80-5d4d-4b7b-8a93-93b3fc176bd2%40googlegroups.com.

Reply via email to