Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test async and teardown #77

Conversation

hutchgrant
Copy link
Member

@hutchgrant hutchgrant commented May 10, 2019

Related Issue

#56

Summary of Changes

  • changed all arrow functions to regular functions, mocha does not like arrow functions, discovered this the hardway
  • fixed async smoke tests, they now run in order, correctly.
  • utilized shared context (this.context) instead of passing context
  • added teardown in after() which runs correctly now that async smoke tests is fixed

@hutchgrant hutchgrant requested a review from thescientist13 May 10, 2019 00:06
@thescientist13 thescientist13 added the chore unit testing, maintenance, etc label May 10, 2019
setup = new TestBed();
context = setup.setupTestBed(__dirname);
this.context = setup.setupTestBed(__dirname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused about the switch to this though. What is this in this context anyway, in the middle of a describe block?

Maybe it's needed to fix this, if so, could you just expand? My only concern is just making sure all these tests remain as isolated as possible.

Copy link
Member Author

@hutchgrant hutchgrant May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/mochajs/mocha/wiki/Shared-Behaviours

If you try to use the context within the describe and not part of this, while using context as a parameter for smokeTests and each test, you will receive the following

  6) Build Greenwood With: 
       Default Greenwood Configuration and Workspace
         Running Smoke Tests: Default Greenwood Configuration and Workspace
           404 (Not Found) page
             "before each" hook for "should have a <script> tag in the <body>":
     TypeError: Cannot read property 'publicDir' of undefined

The reason for that is, when the variable context is initialized in the before() via setup() it's not assigned to the describe's context at all. Because the context.publicDir, isn't working in the smokeTests([], context, label) after. That or we're not accessing the right context, from the child describe, when we're using it as a parameter.

Within each before, it, and after, you can share the same this variables(as long as you don't use arrow functions, test using one you'll see it breaks it).

Copy link
Member Author

@hutchgrant hutchgrant May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has something to do with all our nested describes and shared tests. In any event, yes it's required.

Using context instead of this.context, running

describe('Build Greenwood With: ', function() {
  const LABEL = 'Default Greenwood Configuration and Workspace';
  let setup;
  let context;

  before(function() {
    setup = new TestBed();
    context = setup.setupTestBed(__dirname);
  });
  
  describe(LABEL, function() {
    
    before(async function() {     
      await setup.runGreenwoodCommand('build');
    });
    runSmokeTest(['public', 'index', 'not-found', 'hello'], context, LABEL);
  });

  after(function() {
    setup.teardownTestBed();
  });
});

with smoke-test.js

// TOOD need to find a good Promise based way to call setup.teardownTestBed() after all tests are run
// right now, test files are left over after tests are run, but are cleaned up before each test run
module.exports = runSmokeTest = async function(testCases, context, label) {
  console.log(context);
}

will output undefined.

Also, if you're thinking of putting that runSmokeTest() within a nested test how it was previously, that will also not work because of the teardown. Granted, the context variable will output correctly, but everything else will fail because of teardown.

    it('run smoke test', function() {
      runSmokeTest(['public', 'index', 'not-found', 'hello'], context, LABEL);
    });

output:

  1) Running Smoke Tests: Default Greenwood Configuration and Workspace
       Public Directory Generated Output
         should create a public directory:

      AssertionError: expected false to be true
      + expected - actual

      -false
      +true
      
      at Context.<anonymous> (test/cli/smoke-test.js:11:55)

That error x7. Without teardown in after() yes, this runs correctly.

Trust me, it took a lot of fiddling to get shared tests working.

Copy link
Member

@thescientist13 thescientist13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, wow! Good move. Instead of fighting asycn, let's just go with sync!!! Which is what wanted anyway, haha 🤓

Aside from the question on this.context, I think this entire testing saga is ready to come to an end(game)!

@hutchgrant
Copy link
Member Author

@thescientist13
Copy link
Member

Not sure if you've seen inception, but running through these 3 PRs now feels like the setting up the kicks in the final act of the movie, lol

@thescientist13 thescientist13 merged commit c1bfa08 into technical/issue-56-organize-tests-smoke-test-refactor May 11, 2019
thescientist13 added a commit that referenced this pull request May 11, 2019
* integrating smoke tests

* full smoke test integration

* cleanup

* fix linting

* improve error message

* Fix test async and teardown (#77)

* fix: removed smoke test promises, implemented shared context using this

* fix: remove TODO
thescientist13 added a commit that referenced this pull request May 11, 2019
* WIP tests

* all happy paths for config

* WIP refactoring setup to use cwd context

* WIP refactoring

* more cases working

* cleanup

* formatting

* new nested case

* more cases

* page template case

* clean up tests

* config workspace case

* smoke testing and creating test bed

* using more smoke testing

* added testing for deeper 404 and index testing

* remove eslint

* watch mode

* code coverage and reporting

* reuse test bed

* playing around with smoke tests

* cleanup

* delete fixtures

* remove commented out code

* increase test timeout

* one minute?

* build config error handling

* relax smoke test content testing

* fix spec using hash

* better test and build output cleanup

* Technical/issue 56 organize tests smoke test refactor (#75)

* integrating smoke tests

* full smoke test integration

* cleanup

* fix linting

* improve error message

* Fix test async and teardown (#77)

* fix: removed smoke test promises, implemented shared context using this

* fix: remove TODO
@hutchgrant hutchgrant deleted the technical/issue-56-organize-tests-fix-async-teardown branch May 17, 2019 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore unit testing, maintenance, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants