https://cypress.io logo
Join Discord
Powered by
# e2e-testing
  • b

    bulky-sundown-74498

    07/26/2021, 9:27 PM
    https://docs.cypress.io/api/plugins/writing-a-plugin#List-of-events
  • b

    bulky-sundown-74498

    07/26/2021, 9:28 PM
    You might even be better off with a 'before:run'
  • b

    bulky-sundown-74498

    07/26/2021, 9:28 PM
    because cypress-real-app seems to be seeding the database quite often
  • a

    ancient-wire-34126

    07/27/2021, 4:02 PM
    I don't think that works as expected for some reason: plugins/index.ts
    Copy code
    ts
    /**
     * @type {Cypress.PluginConfig}
     */
    module.exports = (on: any, config: { env: { awsConfig: any } }) => {
      // AWS config
      config.env.awsConfig = awsconfig
    
      console.log('plugins') // this logs
    
      on('before:run', (details) => {
        setA('hello!') // This never seems to run
        console.log('hello')
      })
    
      return config
    }
    spec:
    Copy code
    ts
    import { getA } from '../../data/users'
    
    describe('Login', () => {
    
      // Intercept all calls to Cognito, so we can stub the responses.
      // All OPTIONS (preflight) calls should be successful.
      beforeEach(() => {
        console.log(getA()) // logs null
        cy.visit('login')
      })
  • a

    ancient-wire-34126

    07/27/2021, 4:03 PM
    also console logging in the hook (like the docs do), never seems to show up, so I have a feeling it never actually runs
  • a

    ancient-wire-34126

    07/27/2021, 4:10 PM
    only
    before:browser:launch
    ever triggers
  • a

    ancient-wire-34126

    07/27/2021, 4:12 PM
    Oh, it needs the
    experimentalInteractiveRunEvents
    flag?
  • b

    bulky-sundown-74498

    07/27/2021, 4:13 PM
    Probably, are you using the hooks in open mode?
  • a

    ancient-wire-34126

    07/27/2021, 4:14 PM
    theeeeere we go, yeah open mode is pretty much the go-to for when writing tests locally
  • a

    ancient-wire-34126

    07/27/2021, 4:14 PM
    doesn't seem to use ES modules though :/
  • a

    ancient-wire-34126

    07/27/2021, 4:17 PM
    some-module.ts
    Copy code
    ts
    const a = {
      foo: null,
    }
    
    export const setA = (val) => {
      a.foo = val
    }
    
    export const getA = () => a
    plugin/index.ts
    Copy code
    ts
    import { setA } from '../some-module' 
    module.exports = (on: any, config: { env: { awsConfig: any } }) => {
      on('before:run', (details) => {
        setA('hello!')
      })
    }
    test.spec.ts
    Copy code
    ts
    import { getA } from '../some-module'
    
    describe('Login', () => {
      beforeEach(() => {
        console.log(getA()) // { foo: null } instead of { foo: 'hello!' }
      })
    })
  • b

    bulky-sundown-74498

    07/27/2021, 4:32 PM
    To run plugins, we use ts-node… which is as you can see transforming all modules into commonjs for compatibility…
  • a

    ancient-wire-34126

    07/27/2021, 4:47 PM
    Darn... I thought you said there was ES module support: https://discord.com/channels/755913899261296641/755913900024791046/869329195178811463
  • b

    bulky-sundown-74498

    07/27/2021, 4:48 PM
    I did say that ts files are transformed
  • b

    bulky-sundown-74498

    07/27/2021, 4:48 PM
    In theory you should have to worry about it
  • b

    bulky-sundown-74498

    07/27/2021, 4:49 PM
    It’s only if you count on import.meta that you should face issues
  • a

    ancient-wire-34126

    07/27/2021, 4:49 PM
    My goal is really straightforward: I just want to seed data only once in a JS module, as it's dynamic (e.g. access tokens are generated based on the seed data)
  • b

    bulky-sundown-74498

    07/27/2021, 4:49 PM
    In your plugins file you should use export default instead of module.export
  • a

    ancient-wire-34126

    07/27/2021, 4:50 PM
    ah good catch
  • a

    ancient-wire-34126

    07/27/2021, 4:52 PM
    no dice 😦
  • a

    ancient-wire-34126

    07/27/2021, 4:53 PM
    I wonder if the TS target messes it up
  • a

    ancient-wire-34126

    07/27/2021, 4:58 PM
    esnext
    also doesn't work :/
  • a

    ancient-wire-34126

    07/27/2021, 5:06 PM
    Ok, I might be onto something
  • a

    ancient-wire-34126

    07/27/2021, 5:10 PM
    I only got it working in the plugin file, it seems spec files are not treated as modules :/
  • b

    bulky-sundown-74498

    07/27/2021, 5:28 PM
    No they are not you are right
  • b

    bulky-sundown-74498

    07/27/2021, 5:29 PM
    Unless… you use a preprocessor
  • b

    bulky-sundown-74498

    07/27/2021, 5:31 PM
    Use TypeScript With Cypress | Better world by better software https://glebbahmutov.com/blog/use-typescript-with-cypress/
  • a

    ancient-wire-34126

    07/27/2021, 5:34 PM
    ok, let's give that a shot
  • a

    ancient-wire-34126

    07/27/2021, 5:49 PM
    no dice, just gets stuck here with no errors in the console
  • a

    ancient-wire-34126

    07/27/2021, 5:50 PM
    I'll just ditch it... Maybe at some point we get the option for full ES6 support. I think the demand for transpilation will fade as almost every browser supports ES modules
1...161718...192Latest