Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Template file could not be read during full-app test #76

Closed
noahsw opened this issue Sep 26, 2016 · 11 comments
Closed

Template file could not be read during full-app test #76

noahsw opened this issue Sep 26, 2016 · 11 comments

Comments

@noahsw
Copy link

noahsw commented Sep 26, 2016

I'm trying to write a full-app test of my email's rendering.

However, when I run meteor test --full-app --driver-package practicalmeteor:mocha --port 3100, I see these errors:

error: Could not read template file: weekly-email/template.html mailer

Everything works fine in dev and in production. It's just these full-app tests that can't find the template.

Any ideas?

@johanbrook
Copy link
Contributor

Hi! We're seeing the same output when we're doing full app test too, and I've guessed so far that Meteor is building the app structure differently for those kinds of app startups. I.e. this package can't rely on fetching templates from the private dir. I'm not sure of where those templates are going during app testing.

We're doing some file trickery at the top of this file: https://github.com/lookback/meteor-emails/blob/master/lib/utils.js. As you can see, we use process.env.NODE_ENV to switch things. Is NODE_ENV === 'development' for you during app testing? Thanks!

@noahsw
Copy link
Author

noahsw commented Sep 27, 2016

Thx for the quick reply @johanbrook !

Here's what I have when I run my full app testing:

I20160926-21:06:05.830(-7)? info: Meteor.isTest: false
I20160926-21:06:05.830(-7)? info: Meteor.isAppTest: true
I20160926-21:06:05.831(-7)? info: Meteor.isDevelopment: true
I20160926-21:06:05.831(-7)? info: Meteor.isProduction: false
I20160926-21:10:59.135(-7)? info: process.cwd(): /private/var/folders/p4/466pgnmx7sd_2qwwwl2vc33m0000gn/T/meteor-test-runq2jraw/.meteor/local/build/programs/server
I20160926-21:06:06.294(-7)? info: process.env.BUNDLE_PATH: undefined

If I open /private/var/folders/p4/466pgnmx7sd_2qwwwl2vc33m0000gn/T/meteor-test-runq2jraw/.meteor/local/build/programs/server on my machine, the templates are stored in assets/app.

Looking at https://github.com/lookback/meteor-emails/blob/master/lib/utils.js, I suppose you could use the productionPrivateDir() logic if Meteor.isAppTest = true? Something like that. Not sure what other cases would break.

@thebarty
Copy link
Contributor

Hi guys,

yeah I just ran into this issue, but when running tests in UNIT-testmode, p.e. when running testmode like meteor test --driver-package practicalmeteor:mocha --port 3500.

Did you guys make any projects on this? Did you find a good solution/workaround?

@johanbrook
Copy link
Contributor

Nope, no workaround yet. We can check for test runs with Meteor.isTest and try to find the templates if they're built on another path. But not sure where they're put when testing..

@thebarty
Copy link
Contributor

damn - thats a pitty. I was hoping that this package makes testing easy for me using the render() function... the problem is that even render() will not work and won't find the template

@johanbrook
Copy link
Contributor

Yeah, not sure what's going on there.

@thebarty
Copy link
Contributor

Hi Johan,

I am not into your codebase, but I just scanned https://themeteorchef.com/snippets/using-the-email-package/#tmc-questions-comments. The comments might contain some interesting stuff to improve the code? Check it out and search for Assets.absoluteFilePath and Assets.getText('private/template_name.html'). Does that help in any way?

@johanbrook
Copy link
Contributor

Neat, it was a while ago I looked at those APIs. Might help very much. Will have a look.

@thebarty
Copy link
Contributor

thebarty commented Oct 27, 2016

I don't know if you are much into unit-testing, so this is a little skeleton for you to get started:

run via meteor test --driver-package practicalmeteor:mocha --port 3500

// mailer.test.js
import { Meteor } from 'meteor/meteor'
import { Mailer } from 'meteor/lookback:emails'
import { chai } from 'meteor/practicalmeteor:chai'
const expect = chai.expect

// SERVER TEST
if (Meteor.isServer) {
  describe('Mailer Servertest', () => {
    it('Mailer works in unit test mode', () => {
      const content = Mailer.render('mailTemplate')
      // unfortunatly lookback:emails will NOT throw an error, 
      //  but LOG to the console. So check out the console for errors
    })
  })
}

oh and of course open localhost:3500 in a browser

@thebarty
Copy link
Contributor

Hi guys, I just submitted a pull request. @noahsw: can you check if this works in your app-tests?

@johanbrook
Copy link
Contributor

This is fixed with #78 for me, as seen in #79. Both are merged to masted. Gonna publish fixes as *0.7.6`.

Thanks for your help! 💥

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants