Coder Social home page Coder Social logo

Custom order for running tests about core HOT 6 CLOSED

japa avatar japa commented on August 25, 2024
Custom order for running tests

from core.

Comments (6)

thetutlage avatar thetutlage commented on August 25, 2024

Yup, will be fixed in the next version

from core.

un-versed avatar un-versed commented on August 25, 2024

@thetutlage Actually I created a fork for it, I'm going to make a PR for it.

https://github.com/un-versed/japa

I'm exposing a sort function, that can be used at configure method in japaFile.ts

The code:

japaFile.ts

const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })

/**
 * Configure test runner
 */
configure({
  files: ['test/**/*.spec.ts'],
  before: [
    runMigrations,
    runSeeds,
    startHttpServer,
  ],
  after: [rollbackMigrations],
  sort: collator.compare
})

I'm using a collator, but you can use any sorting function tho

The previous code still works because:
src/SlimRunner/Loader.ts

 /**
  * If _sortFn is defined, then filter the files
  */
    if (typeof (this._sortFn) === 'function') {
      filesPaths = filesPaths.sort(this._sortFn)
    } else {
      filesPaths.sort()
    }

I'm changing my repo to match the CONTRIBUTING.md rn

from core.

thetutlage avatar thetutlage commented on August 25, 2024

Great :) Actually, I am changing the japa a lot. Diving it into a separate runner and separate core. So PR for the old codebase won't help

from core.

un-versed avatar un-versed commented on August 25, 2024

Oh, I got it πŸ‘πŸ» anxious for the new version ☺️

But, there's a chance do add this in the old codebase? Actually I'm using my own package distribution from Japa in npm, just to have this feature in my project.

If there's no chance, I won't write tests for it right now...

from core.

thetutlage avatar thetutlage commented on August 25, 2024

Sure. Feel free to send a PR for the develop branch

from core.

thetutlage avatar thetutlage commented on August 25, 2024

The newer version allows defining a custom function for the files property. You can achieve what you need as follows.

import fastGlob from 'fast-glob'

const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })

files: async () => {
  const files = await fastGlob('tests/**/*.spec.js') 
  return files.sort(collator)
}

Lemme know if you face any issues. We can reopen the issue

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.