Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/jasmine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: jasmine

on:
push:
branches:
- master
paths:
- "jasmine/**"
pull_request:
paths:
- "jasmine/**"
- .github/workflows/jasmine.yaml

env:
LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_JASMINE }}
LAUNCHABLE_DEBUG: 1
LAUNCHABLE_REPORT_ERROR: 1

jobs:
tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: jasmine
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Install Launchable CLI
run: pip install launchable
- name: Launchable verify
run: launchable verify
- name: Install dependencies
run: npm install
- name: Record build
run: launchable record build --name "$GITHUB_RUN_ID"
- name: Save all tests to a file
run: find spec/jasmine_examples -type f > test_list.txt
- name: Run all tests
run: npx jasmine $(cat test_list.txt)
- name: Record tests
run: launchable record tests --base $(pwd) jasmine jasmine-report.json
- name: Request subset
run: cat test_list.txt | launchable subset --target 25% jasmine > subset.txt
- name: Run subset of tests
run: npx jasmine $(cat subset.txt)
5 changes: 5 additions & 0 deletions jasmine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.launchable
.python-version
jasmine-report.json
*.txt
66 changes: 66 additions & 0 deletions jasmine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Jasmine Example Project
=====================

#### Project Structure

```
jasmine
└── spec
├── helpers
│ └── jasmine-json-test-reporter.js
└── jasmine_examples
├── PlayerSpec.js
└── SongSpec.js
```

NOTE: The tests in SongSpec.js are set to fail intentionally.

#### To Build the Project

```
npm install
```

#### To Record Tests

Create test session:

```
BUILD_NAME=jasmine_build
launchable record build --name ${BUILD_NAME}
launchable record session --build ${BUILD_NAME} > session.txt
```

Find and write all tests to a file:

```
find spec/jasmine_examples -type f > test_list.txt
```

To run all tests:

```
npx jasmine $(cat test_list.txt)
```

This creates `jasmine-report.json` in the project root.

Then to record the tests:

```
launchable record tests --base $(pwd) jasmine jasmine-report.json
```

To request subset:

```
cat test_list.txt | launchable subset --target 25% jasmine > subset.txt
```

To run subset of tests:

```
npx jasmine $(cat subset.txt)
```

24 changes: 24 additions & 0 deletions jasmine/lib/jasmine_examples/Player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Player {
play(song) {
this.currentlyPlayingSong = song;
this.isPlaying = true;
}

pause() {
this.isPlaying = false;
}

resume() {
if (this.isPlaying) {
throw new Error('song is already playing');
}

this.isPlaying = true;
}

makeFavorite() {
this.currentlyPlayingSong.persistFavoriteStatus(true);
}
}

module.exports = Player;
8 changes: 8 additions & 0 deletions jasmine/lib/jasmine_examples/Song.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Song {
persistFavoriteStatus(value) {
// something complicated
throw new Error('not yet implemented');
}
}

module.exports = Song;
7 changes: 7 additions & 0 deletions jasmine/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"devDependencies": {
"glob": "^11.0.3",
"jasmine": "^5.12.0",
"jasmine-json-test-reporter": "^1.0.0-beta"
}
}
4 changes: 4 additions & 0 deletions jasmine/spec/helpers/jasmine-json-test-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var JSONReporter = require('jasmine-json-test-reporter');
jasmine.getEnv().addReporter(new JSONReporter({
file: 'jasmine-report.json'
}));
15 changes: 15 additions & 0 deletions jasmine/spec/helpers/jasmine_examples/SpecHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
beforeEach(function () {
jasmine.addMatchers({
toBePlaying: function () {
return {
compare: function (actual, expected) {
const player = actual;

return {
pass: player.currentlyPlayingSong === expected && player.isPlaying
};
}
};
}
});
});
61 changes: 61 additions & 0 deletions jasmine/spec/jasmine_examples/PlayerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const Player = require('../../lib/jasmine_examples/Player');
const Song = require('../../lib/jasmine_examples/Song');

describe('Player', function () {
let player;
let song;

beforeEach(function () {
player = new Player();
song = new Song();
});

it('should be able to play a Song', function () {
player.play(song);
expect(player.currentlyPlayingSong).toEqual(song);

// demonstrates use of custom matcher
expect(player).toBePlaying(song);
});

describe('when song has been paused', function () {
beforeEach(function () {
player.play(song);
player.pause();
});

it('should indicate that the song is currently paused', function () {
expect(player.isPlaying).toBeFalsy();

// demonstrates use of 'not' with a custom matcher
expect(player).not.toBePlaying(song);
});

it('should be possible to resume', function () {
player.resume();
expect(player.isPlaying).toBeTruthy();
expect(player.currentlyPlayingSong).toEqual(song);
});
});

// demonstrates use of spies to intercept and test method calls
it('tells the current song if the user has made it a favorite', function () {
spyOn(song, 'persistFavoriteStatus');

player.play(song);
player.makeFavorite();

expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
});

//demonstrates use of expected exceptions
describe('#resume', function () {
it('should throw an exception if song is already playing', function () {
player.play(song);

expect(function () {
player.resume();
}).toThrowError('song is already playing');
});
});
});
17 changes: 17 additions & 0 deletions jasmine/spec/jasmine_examples/SongSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Player = require('../../lib/jasmine_examples/Player');
const Song = require('../../lib/jasmine_examples/Song');

describe('Song', function () {
let player;
let song;

beforeEach(function () {
player = new Player();
song = new Song();
});

it('should be able to play by player', function () {
player.play(song);
expect(player.isPlaying).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions jasmine/spec/support/jasmine.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
spec_dir: "spec",
spec_files: [
"**/*[sS]pec.?(m)js"
],
helpers: [
"helpers/**/*.?(m)js"
],
env: {
stopSpecOnExpectationFailure: false,
random: true,
forbidDuplicateNames: true
}
}
Loading