Code Monkey home page Code Monkey logo

Comments (6)

samreid avatar samreid commented on August 16, 2024

The proposed strategy may also provide a straightforward way to be able to run unit tests in requirejs mode as well as in compiled mode.

UPDATE: Except we would need to bundle QUnit into our build as a preload or link to an online one.
UPDATE: Also it would be best if unit tests are stripped out during the build.

from aqua.

samreid avatar samreid commented on August 16, 2024

The proposed strategy also provides a straightforward way to run certain tests in PhET-iO mode.

from aqua.

samreid avatar samreid commented on August 16, 2024

I experimented with running tests from main and will put my results here as a "poor man's branch". But I think we should instead investigate generating a new sim-config.js file and sim-test.html file from grunt that are parallel to the existing ones.

from aqua.

samreid avatar samreid commented on August 16, 2024
// faraday's law main:
  if ( phet.chipper.queryParameters.unitTests ) {
    return runUnitTests( faradaysLawUnitTests );
  }

runUnitTests.js

// Copyright 2017, University of Colorado Boulder

/**
 *
 *
 * @author Sam Reid (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var faradaysLaw = require( 'FARADAYS_LAW/faradaysLaw' );

  var runUnitTests = function( tests ) {
    var script = document.createElement( 'script' );
    script.onload = function() {
      tests();

      // Start the tests
      QUnit.start();
    };
    var qunitDiv = document.createElement( 'div' );
    qunitDiv.id = 'qunit';
    document.body.appendChild( qunitDiv );

    var fixtureDiv = document.createElement( 'div' );
    fixtureDiv.id = 'qunit-fixture';
    // document.body.appendChild( fixtureDiv );

    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = '../sherpa/lib/qunit-2.0.1.css';
    link.media = 'all';
    document.head.appendChild( link );

    script.src = '../sherpa/lib/qunit-2.0.1.js';
    document.head.appendChild( script ); //or something of the likes
    document.body.removeChild( document.getElementById( 'splash-container' ) ); //or something of the likes
  };

  faradaysLaw.register( 'runUnitTests', runUnitTests );

  return runUnitTests;
} );

faradaysLawUnitTests.js

// Copyright 2017, University of Colorado Boulder

/**
 *
 *
 * @author Sam Reid (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var faradaysLaw = require( 'FARADAYS_LAW/faradaysLaw' );

  var faradaysLawUnitTests = function() {
    QUnit.test( 'hello test', function( assert ) {
      assert.ok( false, 'false should not be true' );
    } );
  };
  faradaysLaw.register( 'faradaysLawUnitTests', faradaysLawUnitTests );
  return faradaysLawUnitTests;
} );

from aqua.

samreid avatar samreid commented on August 16, 2024

Initial investigation in phetsims/chipper#624 (comment) looks promising, we may continue discussion over there.

from aqua.

samreid avatar samreid commented on August 16, 2024

Let's continue in phetsims/chipper#624 (comment), closing.

from aqua.

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.