Skip to content

Instantly share code, notes, and snippets.

@fred-o
Created February 13, 2020 14:45

Revisions

  1. fred-o created this gist Feb 13, 2020.
    30 changes: 30 additions & 0 deletions jestify.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/bin/bash

    input=$1

    perl -i -pe 's/^( +)(?!expect)([^ ]*q?)(\.should)/$1expect($2)$3/ ' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?(eql|equal)/.$2toEqual/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?be.instance[oO]f/.$2toBeInstanceOf/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?be.empty/.$2toBeEmpty()/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?be.defined/.$2toBeDefined()/' $input
    perl -i -pe 's/\.(should|to)\.(not\.)?be.undefined/.$2toBeUndefined()/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?be.null/.$2toBeNull()/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?have.property/.$2toHaveProperty/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledWith/.$2toHaveBeenCalledWith/' $input
    perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledOnce/.$2toHaveBeenCalledTimes(1)/' $input
    perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledTwice/.$2toHaveBeenCalledTimes(2)/' $input
    perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledThrice/.$2toHaveBeenCalledTimes(3)/' $input
    perl -i -pe 's/\.(should|to)\.(not\.)?have.been.called/.$2toHaveBeenCalled()/' $input

    perl -i -pe 's/\.(should|to)\.(not\.)?have.length\b/.$2toHaveLength/' $input

    perl -i -pe 's/\.toEqual +null/.toBeNull()/' $input

    git diff $input