SlideShare a Scribd company logo
Automating JavaScript testing
   with Jasmine and Perl
        San Diego.pm talk
          Jun 21, 2012
Testing JavaScript: Why
•   The usual unit testing benefits, but also:
•   Improving browser compatibility
•   Catching regressions in your code
•   Catching browser regressions – very
    important!
Testing JavaScript: How
• Many test frameworks out there, none of them as
  advanced and convenient as Test::Harness
• All suffer from JavaScript restrictions on file
  system access, IO, etc.
• Jasmine from Pivotal Labs is touted to be one of
  the best, which I think is true
• But it’s also a pain to use: lots of boilerplate
  HTML just to run a spec, have to manage it all
  manually, etc.
Solution: Test::WWW::Jasmine
• Take Jasmine test specs, run them in Selenium
  controlled browser
• Generate all the boilerplate HTML and
  JavaScript required to run the specs
• Parse Jasmine output, convert it to TAP
• Each describe() is a test, each expect() is a
  subtest
• Test diagnostic printed out with diag(), native
  to TAP::Harness
Example: Jasmine test spec
/*
 * @css /css/css1.css
 * @script script1.js
 */

describe('Test::WWW::Jasmine passing', function() {
    it('should run tests', function() {
        expect(true).toBeTruthy();
        expect(false).toBeFalsy();
        expect(undefined).toBeUndefined();
        expect(null).toBeDefined()
    });
});
Example: test output
1..6
ok 1 - use Test::WWW::Jasmine;
ok 2 - Got object
ok 3 - Right object isa Test::WWW::Jasmine
ok 4 - Parsed all css scripts
ok 5 - Parsed all js scripts
    1..1
        ok 1 - expectation 1
        ok 2 - expectation 2
        ok 3 - expectation 3
        ok 4 - expectation 4
        1..4
    ok 1 - should run tests
ok 6 - jasmine multiple test
Local testing
• Automated testing is good, but it’d be cool if
  we could run the same specs locally while
  developing?
• Enter jasmine.html: JavaScript/HTML spec
  runner that supports the same format as
  Test::WWW::Jasmine
• Runs in browser locally, displays neat HTML
  (Jasmine default, actually)
• Will be released soon, somewhere
Local testing: how results look like
Test::WWW::Jasmine warts
• Work in progress, released to CPAN yesterday
• Needs local (NFS anyone?) HTTP server with
  writable htdocs/something
• Needs browser and Selenium installed
• No headless testing yet (does it make sense?)
• Maybe bundle jasmine.js along
• Maybe run local tinyish HTTP server and serve
  specs off it
Questions? Ideas?
• http://metacpan.org/module/Test::WWW::Jas
  mine
• http://github.com/nohuhu/Test-WWW-
  Jasmine

• Drop me an e-mail: tokarev@cpan.org

More Related Content

PPTX
Developing Rich Internet Applications with Perl and JavaScript
PPTX
Proxying DBI with DBD::Gofer and App::Staticperl
PDF
Why use Go for web development?
PPTX
Ci of js and apex using jasmine, phantom js and drone io df14
PDF
Hello world - intro to node js
PPTX
Saving Time By Testing With Jest
PDF
Asynchronous Programming in Kotlin with Coroutines
PPT
Next generation frontend tooling
Developing Rich Internet Applications with Perl and JavaScript
Proxying DBI with DBD::Gofer and App::Staticperl
Why use Go for web development?
Ci of js and apex using jasmine, phantom js and drone io df14
Hello world - intro to node js
Saving Time By Testing With Jest
Asynchronous Programming in Kotlin with Coroutines
Next generation frontend tooling

What's hot (20)

PPTX
Ruby, the language of devops
PDF
Scala vs ruby
PDF
YAPC::EU 2015 - Perl Conferences
PPTX
Functional Programming in PHP
PDF
Python to go
PDF
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
KEY
About Clack
PDF
Crystal
PPTX
PHP Indonesia - Nodejs Web Development
PDF
Conquering AngularJS Limitations
PPTX
Angular4 kickstart
PPTX
Integration Testing with Selenium
PDF
Riak at Posterous
PDF
Ruby performance - The low hanging fruit
PDF
Unit Testing in JavaScript
PPTX
Hands on Gradle
PPTX
Cypress workshop for JSFoo 2019
PDF
The Many Ways to Test Your React App
PDF
APIs: A Better Alternative to Page Objects
KEY
Ship It ! with Ruby/ Rails Ecosystem
Ruby, the language of devops
Scala vs ruby
YAPC::EU 2015 - Perl Conferences
Functional Programming in PHP
Python to go
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
About Clack
Crystal
PHP Indonesia - Nodejs Web Development
Conquering AngularJS Limitations
Angular4 kickstart
Integration Testing with Selenium
Riak at Posterous
Ruby performance - The low hanging fruit
Unit Testing in JavaScript
Hands on Gradle
Cypress workshop for JSFoo 2019
The Many Ways to Test Your React App
APIs: A Better Alternative to Page Objects
Ship It ! with Ruby/ Rails Ecosystem
Ad

Similar to Automating JavaScript testing with Jasmine and Perl (20)

PDF
Quick tour to front end unit testing using jasmine
PPTX
PPT
Jasmine presentation Selenium Camp 2013
PPT
Jasmine - A BDD test framework for JavaScript
PDF
How do I write Testable Javascript?
PDF
How do I write Testable Javascript
PDF
How do I write testable javascript?
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PDF
Automated Web Testing using JavaScript
PPTX
Testing JavaScript with Jasmine in Rails Applications
PDF
JavaScript TDD with Jasmine and Karma
PDF
Quick tour to front end unit testing using jasmine
PPTX
Jasmine Testing to the Rescue!
PDF
Intro to testing Javascript with jasmine
PDF
Javascript testing: tools of the trade
PDF
3 WAYS TO TEST YOUR COLDFUSION API
PDF
3 WAYS TO TEST YOUR COLDFUSION API -
PDF
Quick Tour to Front-End Unit Testing Using Jasmine
PDF
How to write Testable Javascript
Quick tour to front end unit testing using jasmine
Jasmine presentation Selenium Camp 2013
Jasmine - A BDD test framework for JavaScript
How do I write Testable Javascript?
How do I write Testable Javascript
How do I write testable javascript?
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Automated Web Testing using JavaScript
Testing JavaScript with Jasmine in Rails Applications
JavaScript TDD with Jasmine and Karma
Quick tour to front end unit testing using jasmine
Jasmine Testing to the Rescue!
Intro to testing Javascript with jasmine
Javascript testing: tools of the trade
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API -
Quick Tour to Front-End Unit Testing Using Jasmine
How to write Testable Javascript
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx

Automating JavaScript testing with Jasmine and Perl

  • 1. Automating JavaScript testing with Jasmine and Perl San Diego.pm talk Jun 21, 2012
  • 2. Testing JavaScript: Why • The usual unit testing benefits, but also: • Improving browser compatibility • Catching regressions in your code • Catching browser regressions – very important!
  • 3. Testing JavaScript: How • Many test frameworks out there, none of them as advanced and convenient as Test::Harness • All suffer from JavaScript restrictions on file system access, IO, etc. • Jasmine from Pivotal Labs is touted to be one of the best, which I think is true • But it’s also a pain to use: lots of boilerplate HTML just to run a spec, have to manage it all manually, etc.
  • 4. Solution: Test::WWW::Jasmine • Take Jasmine test specs, run them in Selenium controlled browser • Generate all the boilerplate HTML and JavaScript required to run the specs • Parse Jasmine output, convert it to TAP • Each describe() is a test, each expect() is a subtest • Test diagnostic printed out with diag(), native to TAP::Harness
  • 5. Example: Jasmine test spec /* * @css /css/css1.css * @script script1.js */ describe('Test::WWW::Jasmine passing', function() { it('should run tests', function() { expect(true).toBeTruthy(); expect(false).toBeFalsy(); expect(undefined).toBeUndefined(); expect(null).toBeDefined() }); });
  • 6. Example: test output 1..6 ok 1 - use Test::WWW::Jasmine; ok 2 - Got object ok 3 - Right object isa Test::WWW::Jasmine ok 4 - Parsed all css scripts ok 5 - Parsed all js scripts 1..1 ok 1 - expectation 1 ok 2 - expectation 2 ok 3 - expectation 3 ok 4 - expectation 4 1..4 ok 1 - should run tests ok 6 - jasmine multiple test
  • 7. Local testing • Automated testing is good, but it’d be cool if we could run the same specs locally while developing? • Enter jasmine.html: JavaScript/HTML spec runner that supports the same format as Test::WWW::Jasmine • Runs in browser locally, displays neat HTML (Jasmine default, actually) • Will be released soon, somewhere
  • 8. Local testing: how results look like
  • 9. Test::WWW::Jasmine warts • Work in progress, released to CPAN yesterday • Needs local (NFS anyone?) HTTP server with writable htdocs/something • Needs browser and Selenium installed • No headless testing yet (does it make sense?) • Maybe bundle jasmine.js along • Maybe run local tinyish HTTP server and serve specs off it
  • 10. Questions? Ideas? • http://metacpan.org/module/Test::WWW::Jas mine • http://github.com/nohuhu/Test-WWW- Jasmine • Drop me an e-mail: tokarev@cpan.org

Editor's Notes

  • #7: First 1..1 is subtest that enclose it()1..4 within subtest are actual expect() statements“ok 1” finalizes subtest results“ok 6” finalizes describe()