1
1
function DownloadAtom {
2
2
Write-Host " Downloading latest Atom release..."
3
3
4
- $Source = " https://atom.io/download/windows_zip?channel=stable"
4
+ $Source = " https://atom.io/download/windows_zip?channel=stable"
5
5
$Destination = Join-Path . ' \atom.zip'
6
6
7
7
try {
8
8
Invoke-WebRequest $Source - OutFile $Destination - ErrorAction Stop
9
- } catch {
9
+ }
10
+ catch {
10
11
$PSCmdlet.ThrowTerminatingError ($PSItem )
11
12
}
12
13
@@ -24,7 +25,8 @@ function ExtractAtom {
24
25
try {
25
26
Add-Type - AssemblyName System.IO.Compression.FileSystem
26
27
[System.IO.Compression.ZipFile ]::ExtractToDirectory($ZipFile , $OutPath )
27
- } catch {
28
+ }
29
+ catch {
28
30
$PSCmdlet.ThrowTerminatingError ($PSItem )
29
31
}
30
32
@@ -35,24 +37,27 @@ function ExtractAtom {
35
37
Write-Host " Atom.zip deleted..."
36
38
}
37
39
38
- function ParseJasmine ($String ) {
39
- if ($String -match " ^\s+at.*$" ) {
40
- ' '
41
- return
42
- }
40
+ filter ParseJasmine {
41
+ switch - regex ($_ ) {
42
+ ^\s+ at {
43
+ ' '
44
+ break
45
+ }
43
46
44
- if ( $_ -match " ^\s+it.*$ " ) {
45
- $_ -replace ' ^(\s+)(it)' , ' $1[-] It'
46
- return
47
- }
47
+ ^\s+ it {
48
+ $_ -replace ' ^(\s+)(it)' , ' $1[-] It'
49
+ break
50
+ }
48
51
49
- if ($_ -match " ^\s+Expected.*$" ) {
50
- $x = $_ -replace ' ^(\s*)(Expected)(.*)\s(to equal .*)' , ' $1$2$3%%$1$4'
51
- $x.Replace (' %%' , " `n " )
52
- return
53
- }
52
+ ^\s+ Expected {
53
+ $_ -replace ' ^(\s*)(Expected.*?)\s(instead found .*)' , " `$ 1`$ 2`n`$ 1`$ 3"
54
+ break
55
+ }
54
56
55
- $_
57
+ default {
58
+ $_
59
+ }
60
+ }
56
61
}
57
62
58
63
function ExitWithCode {
@@ -70,15 +75,17 @@ function RunSpecs {
70
75
$specpath = Join-Path . ' \spec'
71
76
72
77
if (Test-Path $specpath ) {
73
- & " $script :ATOM_EXE_PATH " -- test spec * > & 1 | ForEach-Object { ParseJasmine $_ }
74
- } else {
78
+ & $script :ATOM_EXE_PATH -- test $specpath * > & 1 | ParseJasmine
79
+ }
80
+ else {
75
81
throw ' .\spec\ not found.'
76
82
}
77
83
78
84
if ($LASTEXITCODE -ne 0 ) {
79
85
if ($Env: APPVEYOR ) {
80
86
ExitWithCode - exitcode $LASTEXITCODE
81
- } else {
87
+ }
88
+ else {
82
89
throw " One or more tests failed."
83
90
}
84
91
}
0 commit comments