Skip to content

Commit

Permalink
Fix crash when adding first config w/ tests (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg authored Aug 19, 2024
2 parents 926b69d + 1f8895e commit 4f7542b
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 152 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func watchConfig(dataDir string, callback func(appConfig *AppConfig)) {
log.Fatalln("Unable to load config", err)
}
expandWatcher.Close()
collectionsChanged = make(chan fs.Event)
if len(appConfig.ExpandedPaths) > 0 {
expandWatcher, err = fs.NewPathsWatcher(appConfig.ExpandedPaths)
if err != nil {
Expand Down Expand Up @@ -89,6 +90,8 @@ func watchConfig(dataDir string, callback func(appConfig *AppConfig)) {
// Removed item was not a collection dir
continue
}
default:
continue
}
log.Println("collection changed, reloading")
}
Expand Down
4 changes: 4 additions & 0 deletions e2e/configs/holiday.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
collections:
- name: holiday
dirs:
- vacation
102 changes: 52 additions & 50 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.39.0",
"@types/node": "^20.9.0",
"nodemon": "^3.0.1",
"@playwright/test": "^1.44.1",
"@types/node": "^20.12.13",
"nodemon": "^3.1.2",
"npm-run-all": "^4.1.5",
"playwright-bdd": "^5.4.0",
"typescript": "^5.2.2"
"playwright-bdd": "^6.4.0",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { defineBddConfig } from 'playwright-bdd';

const testDir = defineBddConfig({
paths: ['./tests/**/*.feature'],
require: ['./src/**/*.ts'],
steps: ['./src/**/*.ts'],
formatOptions: {
// Fix for ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows
snippetSyntax: './node_modules/playwright-bdd/dist/snippets/snippetSyntaxTs.js'
Expand Down
4 changes: 4 additions & 0 deletions e2e/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class App {
public host: string = 'localhost';
public port: number = 0;
public listenHost: string = '';
public disableAutostart: boolean = true;
proc?: ChildProcess;
exitCode: number | null;
uiLocal: boolean = true;
Expand Down Expand Up @@ -87,6 +88,9 @@ export class App {
this.uiUrl = "http://" + this.listenHost;
}
}
if (!this.stderr) {
this.stderr = "";
}
this.stderr += msg;
});
this.proc.on('close', (code) => {
Expand Down
24 changes: 23 additions & 1 deletion e2e/src/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ Given('the config {string}', async ({ app }, p: string) => {
await fs.copyFile(configPath, app.path("configuration.yaml"));
});

When('the user adds the config {string}', async ({ app }, p: string) => {
const configPath = path.resolve(__dirname, "..", "configs", p);
await fs.copyFile(configPath, app.path("configuration.yaml"));
});

async function addFiles(dataTable: DataTable, app: App) {
if (!app.cwd) {
await app.useTempDir();
console.log("CWD:", app.cwd);
}
for (const row of dataTable.rows()) {
const [src, dst] = row;
const srcPath = path.resolve(__dirname, "..", src);
Expand Down Expand Up @@ -48,6 +57,11 @@ Given('a running app', async ({ app }) => {
}).toPass();
});

Given('no running app', async ({ app }) => {
app.disableAutostart = true;
await app.stop();
});

When('the API goes down', async ({ app }) => {
await app.stop();
});
Expand Down Expand Up @@ -78,7 +92,14 @@ When('waits a second', async ({ page }) => {
await page.waitForTimeout(1000);
});

When('the user opens the home page', async ({ app }) => {
When('(the user )opens the home page', async ({ app }) => {
if (!app.proc && !app.disableAutostart) {
await app.run();
await expect(async () => {
expect(app.stderr).toContain("app running");
}
).toPass();
}
await app.goto("/");
});

Expand Down Expand Up @@ -126,6 +147,7 @@ Then('the file {string} does not exist', async ({ app }, filePath: string) => {
await fs.stat(app.path(filePath));
throw new Error("File exists");
} catch (error) {
console.log("Error:", error);
expect(error.code).toBe('ENOENT');
}
});
Expand Down
1 change: 1 addition & 0 deletions e2e/tests/connection-error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Feature: Connection Error Message

Scenario: UI loads, but API is down
Given an empty working directory
And no running app
When the user opens the home page
Then the page shows "Connection error"

Expand Down
Loading

0 comments on commit 4f7542b

Please sign in to comment.