Cannot run tests on CD/CI Bitbucket Pipeline

Hello,

I have tests cases and I tried to setup a pipeline on my Bitbucket repository so that every time a merge request is created, the pipeline runs the tests on the branch so that nothing broke.

When I open the console in my folder and run the command adonis test is goes successfully well but in the Docker environment it keeps failing with various errors. The latest one being that it cannot find an .env file

I have attached the pipeline logs here:

pipelineLog-258.txt

Package version

5.0.9

Node.js and npm version

Node.js 10.15 and npm 6.9

Sample Code (to reproduce the issue)

image: node:10.15.0

pipelines:
  pull-requests:
      '**':
        - step:
            name: Build and test
            script:
              - npm i -g @adonisjs/cli
              - npm i
              - adonis test
1 Like

After playing around, I updated the pipeline like so:

image: node:10.15.0

pipelines:
  pull-requests:
      '**':
        - step:
            name: Build and test
            script:
              - npm i -g @adonisjs/cli
              - npm i
              - cp .env.example .env
              - adonis test

However I now get the following error:

+ adonis test
[SyntaxError: Unexpected token =
at /opt/atlassian/pipelines/agent/build/app/Models/Practice.js (/opt/atlassian/pipelines/agent/build/app/Models/Practice.js:1:1)]

However there is no such typo in the file. The start of my Models/Practice file looks like this:

'use strict';

const moment = require('moment');
const Env = use('Env');
const Mail = use('Mail');
const Hash = use('Hash');

/** @type {Model} */
const Model = use('Model');

class Practice extends Model {
// Model definition here.....
2 Likes

Never used Atlassin stuff, but there are two things:

  1. Env thing that you solved
  2. Tests wrap code, so when it shows Practise.js:1:1 it might actually be in somewhere else in that file. Can’t remember if that was thing in AdonisJS tests too but that’s what Mocha + Chai tests show in Express

Edit: Does your .env.example contain APP_KEY too?

I don’t use node image because it goes nut and gives me errors.

Been a while since I used this but it should work

image: atlassian/default-image:2

pipelines:
  default:
    - step:
        caches:
          - node
        script: # Modify the commands below to build your repository.
          - npm install
          - apt-get update &&  
                 apt-get install -yq --no-install-recommends  
                 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3  
                 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4  
                 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1  
                 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6  
                 libnss3 
          - cp .env.example .env
          - node ace test